public ActionResult SuaNSX(String id, HttpPostedFileBase logoHSX) { ViewBag.MaHang = new SelectList(db.HangSXes.ToList().OrderBy(n => n.TenHang), "MaHang", "TenHang"); HangSX hang = db.HangSXes.SingleOrDefault(n => n.MaHang == id); if (logoHSX == null) { ViewBag.Thongbao = "Vui lòng chọn ảnh mới"; UpdateModel(hang); db.SubmitChanges(); } else { if (ModelState.IsValid) { var fileName = Path.GetFileName(logoHSX.FileName); var path = Path.Combine(Server.MapPath("~/images"), fileName); if (System.IO.File.Exists(path)) { ViewBag.Thongbao = "Hình ảnh đã tồn tại"; } else { logoHSX.SaveAs(path); } hang.Logo = fileName; UpdateModel(hang); db.SubmitChanges(); } } return(RedirectToAction("NhaSanXuat", "Admin")); }
public IHttpActionResult PostHangSX(HangSX hangSX) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.hangSXs.Add(hangSX); try { db.SaveChanges(); } catch (DbUpdateException) { if (HangSXExists(hangSX.IDHSX)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = hangSX.IDHSX }, hangSX)); }
public IHttpActionResult PutHangSX(string id, HangSX hangSX) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != hangSX.IDHSX) { return(BadRequest()); } db.Entry(hangSX).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!HangSXExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
// GET: Administrator/HangSXes/Delete/5 public ActionResult Delete(int[] idHang) { foreach (var i in idHang) { HangSX hsx = db.HangSXes.Find(i); db.HangSXes.Remove(hsx); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "IdHang,Mota,Website,LienHe,UTien,ThucThi,NgonNgu")] HangSX hangSX) { if (ModelState.IsValid) { db.Entry(hangSX).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hangSX)); }
public ActionResult Create([Bind(Include = "IdHang,Mota,Website,LienHe,UTien,ThucThi,NgonNgu")] HangSX hangSX) { if (ModelState.IsValid) { db.HangSXes.Add(hangSX); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hangSX)); }
public IHttpActionResult GetHangSX(string id) { HangSX hangSX = db.hangSXs.Find(id); if (hangSX == null) { return(NotFound()); } return(Ok(hangSX)); }
public ActionResult SuaNSX(string id) { HangSX hsx = db.HangSXes.SingleOrDefault(n => n.MaHang == id); if (hsx == null) { Response.StatusCode = 404; return(null); } return(View(hsx)); }
public ActionResult ChiTietNSX(string id) { HangSX hsx = db.HangSXes.SingleOrDefault(n => n.MaHang == id); //ViewBag.MaDienThoai = dt.MaDienThoai; if (hsx == null) { Response.StatusCode = 404; return(null); } return(View(hsx)); }
public IHttpActionResult PostHangSX(HangSX hangSX) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.HangSXes.Add(hangSX); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = hangSX.IdHang }, hangSX)); }
// GET: Administrator/HangSXes/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HangSX hangSX = db.HangSXes.Find(id); if (hangSX == null) { return(HttpNotFound()); } return(View(hangSX)); }
public IHttpActionResult DeleteHangSX(string id) { HangSX hangSX = db.hangSXs.Find(id); if (hangSX == null) { return(NotFound()); } db.hangSXs.Remove(hangSX); db.SaveChanges(); return(Ok(hangSX)); }
public HangSX getElement(string id) { string query = "select * from HANGSX where MAHSX = '" + id + "'"; DataTable dataTable = DocCSDL(query); HangSX hangSX1 = null; if (dataTable != null || dataTable.Rows.Count != 0) { int ma = Convert.ToInt32(dataTable.Rows[0][0]); string ten = dataTable.Rows[0][1].ToString(); string quocGia = dataTable.Rows[0][2].ToString(); hangSX1 = new HangSX(ma, ten, quocGia); } return(hangSX1); }
public ActionResult Create(HangSX a) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:54779/api/"); var postTask = client.PostAsJsonAsync("HangSXAdmin", a); postTask.Wait(); var kq = postTask.Result; if (kq.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } ModelState.AddModelError(string.Empty, "Error"); return(View(a)); }
public ActionResult Edit(HangSX a) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:54779/api/"); var putTask = client.PutAsJsonAsync("HangSXAdmin/" + a.IdHang, a); putTask.Wait(); var kq = putTask.Result; if (kq.IsSuccessStatusCode) { return(RedirectToAction("Index")); } return(View(a)); } }
public IHttpActionResult PutHangSX(int id, HangSX hangSX) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != hangSX.IdHang) { return(BadRequest()); } db.Entry(hangSX).State = EntityState.Modified; db.SaveChanges(); return(StatusCode(HttpStatusCode.NoContent)); }
public ViewResult sanPhamTheoHang(string MaHSX = "SSU") { HangSX hangSX = db.HangSXes.SingleOrDefault(n => n.MaHSX == MaHSX); if (hangSX == null) { Response.StatusCode = 404; return(null); } List <SanPham> lstSanPham = db.SanPhams.Where(n => n.MaHSX == MaHSX).OrderBy(n => n.MaHSX).ToList(); if (lstSanPham.Count == 0) { ViewBag.SanPham = "Không có sản phẩm nào!"; } ViewBag.lstSanPham = db.SanPhams.ToList(); return(View(lstSanPham)); }
// GET: Admin/NguoiDungs/Edit/5 public ActionResult Edit(int id) { HangSX hangSX = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:54779/api/"); var edit = client.GetAsync("HangSXAdmin/?id=" + id.ToString()); edit.Wait(); var kq = edit.Result; if (kq.IsSuccessStatusCode) { var readTask = kq.Content.ReadAsAsync <HangSX>(); readTask.Wait(); hangSX = readTask.Result; } } return(View(hangSX)); }
public ActionResult XacNhanXoaNSX(string id) { try { HangSX hsx = db.HangSXes.SingleOrDefault(n => n.MaHang == id); var kt = db.Giays.Where(x => x.MaHang == id).ToList(); //if (hsx == null) //{ // response.statuscode = 404; // return null; //} if (kt != null) { ViewData["Error"] = "Vui lòng xóa sản phẩm thuộc hãng giày này trước"; db.SubmitChanges(); return(RedirectToAction("NhaSanXuat")); } db.HangSXes.DeleteOnSubmit(hsx); } catch (Exception ex) { ViewBag.onError = "Vui lòng xóa sản phẩm thuộc hãng giày này trước"; //db.SubmitChanges(); return(RedirectToAction("NhaSanXuat")); } //HangSX hsx = db.HangSXes.SingleOrDefault(n => n.MaHang == id); //if (hsx == null) //{ // Response.StatusCode = 404; // return null; //} //db.HangSXes.DeleteOnSubmit(hsx); //db.SubmitChanges(); return(RedirectToAction("NhaSanXuat")); }
public ActionResult ThemNSX(HangSX hsx, HttpPostedFileBase logoNSX, FormCollection fc) { var MaHang = fc["MaHang"]; var khoa = db.HangSXes.Where(x => x.MaHang.Equals(MaHang)).ToList(); if (khoa.Count == 0) { if (logoNSX == null) { ViewBag.Thongbao = "Vui lòng chọn hình ảnh"; return(View()); } else { var filename = Path.GetFileName(logoNSX.FileName); var path = Path.Combine(Server.MapPath("~/images"), filename); if (System.IO.File.Exists(path)) { ViewBag.Thongbao = "Hình ảnh đã tồn tại"; } else { logoNSX.SaveAs(path); } hsx.MaHang = MaHang; hsx.Logo = filename; db.HangSXes.InsertOnSubmit(hsx); db.SubmitChanges(); } return(RedirectToAction("NhaSanXuat")); } else { ViewData["loi"] = "Mã hãng này bị trùng"; } return(this.ThemNSX()); }