You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
157 lines
3.1 KiB
157 lines
3.1 KiB
using AspNetFrameworkMVC.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
|
|
namespace AspNetFrameworkMVC.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
public ActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public ActionResult About()
|
|
{
|
|
ViewBag.Message = "Your application description page.";
|
|
|
|
return View();
|
|
}
|
|
|
|
public ActionResult Contact()
|
|
{
|
|
ViewBag.Message = "Your contact page.";
|
|
|
|
return View();
|
|
}
|
|
|
|
public ActionResult NewGuid()
|
|
{
|
|
string guid = Guid.NewGuid().ToString();
|
|
|
|
return Content(guid);
|
|
}
|
|
|
|
[HttpPost]
|
|
public HttpResponseMessage UploadSample()
|
|
{
|
|
HttpRequestBase req = HttpContext.Request;
|
|
|
|
if (req.Files.Count < 1)
|
|
return new HttpResponseMessage(HttpStatusCode.BadRequest);
|
|
|
|
foreach (string file in req.Files)
|
|
{
|
|
HttpPostedFileBase uploadFile = req.Files[file];
|
|
string outputFilePath = HttpContext.Server.MapPath($"~/Uploads/{uploadFile.FileName}");
|
|
uploadFile.SaveAs(outputFilePath);
|
|
}
|
|
|
|
return new HttpResponseMessage(HttpStatusCode.OK);
|
|
}
|
|
|
|
[HttpGet]
|
|
public FileResult DownloadSample()
|
|
{
|
|
string filename = Request.QueryString["filename"];
|
|
string filePath = HttpContext.Server.MapPath($"~/Uploads/{filename}");
|
|
|
|
byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
|
|
return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Zip, Path.GetFileName(filePath));
|
|
}
|
|
|
|
public ActionResult CheckLogin()
|
|
{
|
|
string filename = Request.QueryString["username"];
|
|
string password = Request.QueryString["password"];
|
|
|
|
bool result = LoginManager.CheckLogin(filename, password);
|
|
return Content($"CheckLogin: {result}");
|
|
}
|
|
|
|
public ActionResult MyView(int id)
|
|
{
|
|
ViewBag.Title = id + " 자료";
|
|
|
|
ViewData["MethodName"] = nameof(NoMethod);
|
|
|
|
Guest guest = new Guest
|
|
{
|
|
Id = 1,
|
|
Name = "Alex",
|
|
CreatedDate = DateTime.Now,
|
|
Message = "Congratulation!"
|
|
};
|
|
|
|
return View(guest);
|
|
}
|
|
|
|
private void NoMethod()
|
|
{
|
|
return;
|
|
}
|
|
|
|
public ActionResult MyViewRazor(int count)
|
|
{
|
|
ViewBag.Count = count;
|
|
|
|
return View();
|
|
}
|
|
|
|
public ActionResult GuestRazor()
|
|
{
|
|
ViewBag.Title = "😎 Guest Razor 😎";
|
|
|
|
Guest guest = new Guest
|
|
{
|
|
Id = 3,
|
|
Name = "Richard",
|
|
CreatedDate = DateTime.Now,
|
|
Message = "Here comes new chanllenger 🥳"
|
|
};
|
|
|
|
return View(guest);
|
|
}
|
|
|
|
public ActionResult AddGuest()
|
|
{
|
|
string name = Request["name"];
|
|
string msg = Request["msg"];
|
|
|
|
var db = new GuestDbContext();
|
|
Guest g = new Guest()
|
|
{
|
|
Name = name,
|
|
CreatedDate = DateTime.Now,
|
|
Message = msg
|
|
};
|
|
|
|
db.Guests.Add(g);
|
|
db.SaveChanges();
|
|
|
|
return RedirectToAction("ShowGuests");
|
|
}
|
|
|
|
public ActionResult ShowGuests()
|
|
{
|
|
var db = new GuestDbContext();
|
|
List<Guest> guests = db.Guests.OrderByDescending(g => g.Id).Take(10).ToList();
|
|
|
|
return View(guests);
|
|
}
|
|
|
|
public ActionResult Guest(int id)
|
|
{
|
|
var db = new GuestDbContext();
|
|
Guest guest = db.Guests.Where(g => g.Id == id).FirstOrDefault();
|
|
|
|
return View(guest);
|
|
}
|
|
}
|
|
} |