public IActionResult Post(Promotion data) { data.isActive = true; var createdPromotion = service.Add(data); return(CreatedAtAction("Get", new { id = createdPromotion.Data.Id }, createdPromotion)); }
public ActionResult Create(Promotion promotion) { _promotionService.Add(promotion); _promotionService.Save(); int lastpage = _promotionService.GetTotalPage(_promotionService.GetActive().Count(), itemperpage); return(RedirectToAction("Index", new { page = lastpage })); }
public ActionResult Create(PromotionViewModel promotionVm, HttpPostedFileBase fileUpload) { string pathImage = string.Empty; //kiểm tra và thêm dữ liệu vào database if (ModelState.IsValid) { string filePathSave = string.Empty; //check image resource if (fileUpload == null) { //đặt đường dẫn ảnh mặc định filePathSave = "404.png"; } else { filePathSave = Path.GetFileName(fileUpload.FileName); pathImage = Path.Combine(Server.MapPath("~/Content/Promotion"), filePathSave); if (System.IO.File.Exists(pathImage)) { //Hình ảnh đã tồn tại return(RedirectToAction("Index", "Home")); } else { //Lưu tên file sẽ insert vào filePathSave = fileUpload.FileName; } } //update model từ view lên controller //cập nhật thời gian, tên ảnh, người thực hiện, mã của sản phẩm - thiếu người thực hiện promotionVm.PromotionPoster = filePathSave; promotionVm.CreatedDate = DateTime.Now; Promotion result = new Promotion(); result.UpdatePromotion(promotionVm); var resultPromotion = _promotionService.Add(result); if (resultPromotion == null) { return(RedirectToAction("Index", "Home")); } else { if (filePathSave != "404.png") { fileUpload.SaveAs(pathImage); } _promotionService.SaveChanges(); SetAlert("Thêm ưu đãi thành công!", CommonConstrants.SUCCESS_ALERT); return(RedirectToAction("Index", "Promotion")); } } ViewBag.PromotionStatusID = new SelectList(_statusService.GetAll(), "StatusID", "StatusName"); return(View(promotionVm)); }
public string AddPromotion([FromBody] Promotion promo) { if (_svc.Add(promo)) { return(StatusCodes.Status201Created.ToString()); } else { return(StatusCodes.Status400BadRequest.ToString()); } }
public ActionResult RiseAdd(Promotion promotion) { _promotionService.Add(promotion); return(RedirectToAction("")); }
public IActionResult Create(Promotion promotion) { if (HttpContext.Session.GetString("Name") == null) { return(RedirectToAction("Login", "Admin")); } if (promotion.Order != 0) { var result = promotionService.Get(x => x.Order == promotion.Order && x.isDelete == false).Data; if (promotion.Id == 0) { if (result == null) { var kayıt = promotionService.Add(promotion); TempData["Mesaj"] = kayıt.BasariliMi ? "Kayıt Eklendi." : kayıt.Mesaj; return(RedirectToAction("Create", "Promotion")); } else { TempData["Mesaj"] = "Aynı sıra numarasına ait iki kayıt olamaz."; return(View()); } } else { var kayıt = promotionService.Get(x => x.Id == promotion.Id).Data; if (result == null) { promotion.imageUrl = kayıt.imageUrl; promotion.isActive = kayıt.isActive; promotion.GetHomepage = kayıt.GetHomepage; promotionService.Update(promotion); return(RedirectToAction("Index", "Promotion")); } else { if (result.Order == kayıt.Order) { promotion.imageUrl = kayıt.imageUrl; promotion.isActive = kayıt.isActive; promotion.GetHomepage = kayıt.GetHomepage; promotionService.Update(promotion); return(RedirectToAction("Index", "Promotion")); } else { TempData["Mesaj"] = "Aynı sıra numarasına ait iki kayıt olamaz."; return(View()); } } } } else { TempData["Mesaj"] = "Sıra numarası giriniz."; return(View()); } }