public ActionResult AddCakesData(CakeViewModel model) { if (!ModelState.IsValid) { return(View(model)); } MyMapper <Cake, CakeViewModel> _mapper = new MyMapper <Cake, CakeViewModel>(); Cake cakeDataModel = _mapper.castTo(model); _repository.Add(cakeDataModel); string imageUrl = model.Name + "_" + cakeDataModel.Id + ".jpg"; string fileName = Server.MapPath("../images/" + imageUrl); var file = Request.Files["myimage"]; file.SaveAs(fileName); cakeDataModel.ImageUrl = imageUrl; _repository.Update(cakeDataModel); return(RedirectToAction("Index")); }
public ActionResult AddCakes(CakeViewModel model) { if (!ModelState.IsValid) { return(View(model)); } Cake cakeDataModel = new Cake(); cakeDataModel.Id = model.Id; cakeDataModel.Name = model.Name; cakeDataModel.Price = model.Price; cakeDataModel.Description = model.Description; Model1 ctx = new Model1(); ctx.Cakes.Add(cakeDataModel); ctx.SaveChanges(); string fileName = Server.MapPath("../images/" + model.Name + "_" + model.Id + ".jpg"); var file = Request.Files["myimage"]; file.SaveAs(fileName); model.ImageUrl = model.Name + "_" + model.Id + ".jpg"; ctx.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Detail(int id) { Cake entity = _repository.Find(id); MyMapper <CakeViewModel, Cake> _mapper = new MyMapper <CakeViewModel, Cake>(); CakeViewModel model = _mapper.castTo(entity); return(View(model)); }
public ActionResult CommentsPartial(int id) { var repository = new PatisserieRepository(); Cake entity = _repository.Find(id); MyMapper <CakeViewModel, Cake> _mapper = new MyMapper <CakeViewModel, Cake>(); CakeViewModel model = _mapper.castTo(entity); return(View(model)); }
public IActionResult Create(CakeViewModel cake) { if (ModelState.IsValid) { _cakeService.Create(cake); return(RedirectToAction("Index")); } return(View(cake)); }
public IActionResult Index() { var cakes = _cakeRepository.GetAllCakes().OrderBy(c => c.Name); var cakeViewModel = new CakeViewModel() { Cakes = cakes.ToList(), Title = "Welcome to our delicious cakes" }; return(View(cakeViewModel)); }
public IActionResult CreateCake(CakeViewModel model) { if (ModelState.IsValid) { var cake = cakeRepository.Create(new Cake() { CategoryId = model.CategoryId, ExpiryDate = model.ExpiryDate, Ingredient = model.Ingredient, ManufacturingDate = model.ManufacturingDate, Name = model.Name, IsDeleted = false, Price = model.Price }); return(RedirectToAction("ViewCake", "Home", new { id = cake.CakeId })); } ModelState.AddModelError("", "Có lỗi trong quá trình thực hiện, xin hãy thử lại!"); return(View()); }
public ActionResult Detail(int id) { Model1 ctx = new Model1(); Cake entity = ctx.Cakes.Where(c => c.Id == id).FirstOrDefault(); CakeViewModel model = new CakeViewModel(); model.Id = entity.Id; model.Name = entity.Name; model.Price = entity.Price; model.ImageUrl = entity.ImageUrl; model.Comments = new List <CommentViewModel>(); foreach (var item in entity.Comments) { CommentViewModel cmModel = new CommentViewModel(); cmModel.Id = item.Id; cmModel.CommentStr = item.CommentStr; cmModel.User = item.User; model.Comments.Add(cmModel); } return(View(model)); }
public ActionResult Details(int id) { CakeViewModel model = adapter.GetDetails(id); return(View(model)); }