public ActionResult ThemThuongHieu(THUONG_HIEU th, FormCollection c, HttpPostedFileBase fileUpload) { var ten = c["TenTH"]; var ma = c["MaTH"]; //var hinh = c["fileUpload"]; if (string.IsNullOrEmpty(ma)) { ViewData["Loi"] = "Mã thương hiệu không được để trống"; return(View()); } if (string.IsNullOrEmpty(ten)) { ViewData["Loi"] = "Tên thương hiệu không được để trống"; return(View()); } if (fileUpload == null || fileUpload.ContentLength == 0) { ViewData["Loi"] = "Vui lòng chọn ảnh bìa"; return(View()); } // else { if (ModelState.IsValid) { var fileName = Path.GetFileName(fileUpload.FileName); var path = Path.Combine(Server.MapPath("~/HinhAnh/ThuongHieu/"), fileName); if (System.IO.File.Exists(path)) { ViewData["Loi"] = "Hình ảnh đã tồn tại"; return(View()); } else { fileUpload.SaveAs(path); } try { th.MaTH = ma; th.TenTH = ten; th.Images = fileName; data.THUONG_HIEUs.InsertOnSubmit(th); data.SubmitChanges(); } catch (Exception) { ViewData["Loi"] = "Mã thương hiệu đã tồn tại."; return(View()); } } return(RedirectToAction("ThuongHieu")); } }
public ActionResult XoaThuongHieu(string id, FormCollection c) { var kt = data.SAN_PHAMs.Where(t => t.MaTH == id).Count(); if (kt == 0) { THUONG_HIEU xoa = data.THUONG_HIEUs.Where(t => t.MaTH == id).FirstOrDefault(); data.THUONG_HIEUs.DeleteOnSubmit(xoa); data.SubmitChanges(); return(RedirectToAction("ThuongHieu")); } else { return(RedirectToAction("KhongTheXoa", "Admin")); } }
public HttpResponseMessage Create(HttpRequestMessage request, THUONG_HIEU thuongHieuModel) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (ModelState.IsValid) { request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { var thuongHieu = _thuongHieuService.Add(thuongHieuModel); _thuongHieuService.SaveChanges(); response = request.CreateResponse(HttpStatusCode.Created, thuongHieu); } return response; })); }
public ActionResult SuaThuongHieu(string id, FormCollection c, HttpPostedFileBase file) { THUONG_HIEU sua = data.THUONG_HIEUs.First(m => m.MaTH == id); var ten = c["TenTH"]; if (string.IsNullOrEmpty(ten)) { ViewData["Loi"] = "Tên thương hiệu không được để trống"; } if (file == null) { ViewBag.Thongbao = "Vui lòng chọn ảnh bìa"; return(View()); } else { if (ModelState.IsValid) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/HinhAnh/ThuongHieu"), fileName); if (System.IO.File.Exists(path)) { ViewBag.Thongbao = "Hình ảnh đã tồn tại"; } else { file.SaveAs(path); } sua.TenTH = ten; sua.Images = fileName; UpdateModel(sua); data.SubmitChanges(); return(RedirectToAction("ThuongHieu", "Admin")); } return(this.SuaThuongHieu(id)); } }
public void Update(THUONG_HIEU thuongHieu) { _thuongHieuRepository.Update(thuongHieu); }
public THUONG_HIEU Add(THUONG_HIEU thuongHieu) { return(_thuongHieuRepository.Add(thuongHieu)); }
public ActionResult SuaThuongHieu(string id) { THUONG_HIEU sua = data.THUONG_HIEUs.First(m => m.MaTH == id); return(View(sua)); }