public HttpResponseMessage KhoaMo(HttpRequestMessage request, int id) { ThuCung modelThuCung = null; try { _thuCungService.KhoaMo(id); _thuCungService.SaveChange(); modelThuCung = _thuCungService.GetById(id); if (modelThuCung != null) { if (modelThuCung.TrangThai != null && (bool)modelThuCung.TrangThai) { Message = "Mở thú cưng thành công"; } else { Message = "Khóa thú cưng thành công"; } } else { throw new DbEntityValidationException("Khóa mở thú cưng không thành công"); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, modelThuCung)); }
public ActionResult DeleteConfirmed(int id) { ThuCung thuCung = db.ThuCungs.Find(id); db.ThuCungs.Remove(thuCung); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Index(int ID) { ThuCung pet = db.ThuCungs.Find(ID); if (pet == null) { return(View("Error")); } return(View(pet)); }
public ActionResult Index() { var kq = db.ChiTietDonHangs.GroupBy(x => x.MaThuCung).Select(x => new { id = x.Key, sl = x.Count() }); var rs = kq.OrderByDescending(s => s.sl).Take(6); List <ThuCung> p = new List <ThuCung>(); foreach (var item in rs) { ThuCung pet = db.ThuCungs.SingleOrDefault(x => x.MaThuCung == item.id); p.Add(pet); } return(View(p.Take(6))); }
public ActionResult Create([Bind(Include = "MaThuCung,TenThuCung,MauLong,CanNang,Tuoi,MaLoai,MaChungLoai,HinhAnh,Gia,MoTa,SoLuong")] ThuCung thuCung) { if (ModelState.IsValid) { db.ThuCungs.Add(thuCung); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaChungLoai = new SelectList(db.ChungLoais, "MaChungLoai", "TenChungLoai", thuCung.MaChungLoai); ViewBag.MaLoai = new SelectList(db.Loais, "MaLoai", "TenLoai", thuCung.MaLoai); return(View(thuCung)); }
// GET: Admin/ManagermentThuCungs/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ThuCung thuCung = db.ThuCungs.Find(id); if (thuCung == null) { return(HttpNotFound()); } return(View(thuCung)); }
public ActionResult Add(int ID) { GioHang giohang = GetCart(); ThuCung x = db.ThuCungs.Find(ID); if (x == null) { return(View("Error")); } SanPham p = new SanPham(x.MaThuCung, x.TenThuCung, x.HinhAnh, (long)x.Gia, 1); giohang.AddToCart(p); return(RedirectToAction("Index")); }
// GET: Admin/ManagermentThuCungs/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ThuCung thuCung = db.ThuCungs.Find(id); if (thuCung == null) { return(HttpNotFound()); } ViewBag.MaChungLoai = new SelectList(db.ChungLoais, "MaChungLoai", "TenChungLoai", thuCung.MaChungLoai); ViewBag.MaLoai = new SelectList(db.Loais, "MaLoai", "TenLoai", thuCung.MaLoai); return(View(thuCung)); }
public HttpResponseMessage Delete(HttpRequestMessage request, int id) { ThuCung modelThuCung = null; try { var listCanNang = _canNangService.GetAll(); foreach (var item in listCanNang) { if (item.IdThuCung != id) { continue; } _canNangService.GetById(item.IdCanNang); _canNangService.Delete(item.IdCanNang); } _thuCungService.SaveChange(); var listTinhTrang = _tinhTrangService.GetAll(); foreach (var item in listTinhTrang) { if (item.IdThuCung != id) { continue; } _tinhTrangService.GetById(item.IdTinhTrang); _tinhTrangService.Delete(item.IdTinhTrang); } _thuCungService.SaveChange(); modelThuCung = _thuCungService.Delete(id); if (modelThuCung != null) { Message = "Xóa thú cưng thành công"; _thuCungService.SaveChange(); } else { throw new DbEntityValidationException("Xóa thú cưng không thành công"); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, modelThuCung)); }
public ActionResult Edit([Bind(Include = "MaThuCung,TenThuCung,MauLong,CanNang,Tuoi,MaLoai,MaChungLoai,HinhAnh,Gia,MoTa,SoLuong")] ThuCung thuCung) { if (ModelState.IsValid) { var file = Request.Files["HinhAnh"]; if (file.FileName != null && file.ContentLength > 0) { string path = Server.MapPath("~/Content/img/Pet/" + file.FileName); file.SaveAs(path); thuCung.HinhAnh = file.FileName; } db.Entry(thuCung).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaChungLoai = new SelectList(db.ChungLoais, "MaChungLoai", "TenChungLoai", thuCung.MaChungLoai); ViewBag.MaLoai = new SelectList(db.Loais, "MaLoai", "TenLoai", thuCung.MaLoai); return(View(thuCung)); }
public HttpResponseMessage GetById(HttpRequestMessage request, int id) { ThuCung thuCungSingler = null; try { thuCungSingler = _thuCungService.GetById(id); if (thuCungSingler != null) { Message = "Thông tin thú cưng với id: " + id; } else { throw new DbEntityValidationException(string.Format("Không tìm kiếm được thú cưng với id {0}", id)); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, thuCungSingler)); }
public HttpResponseMessage Update(HttpRequestMessage request, ThuCung thuCung) { ThuCung modelThuCung = null; try { _thuCungService.Update(thuCung); _thuCungService.SaveChange(); modelThuCung = _thuCungService.GetById(thuCung.IdThuCung); if (modelThuCung != null) { Message = "Tạo mới tài khoản thành công"; } else { throw new DbEntityValidationException("tạo tài khoản không thành công"); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, modelThuCung)); }
public HttpResponseMessage Create(HttpRequestMessage request, ThuCung thuCung) { ThuCung modelThuCung = null; try { thuCung.NgayNuoi = DateTime.Now; modelThuCung = _thuCungService.Add(thuCung); if (modelThuCung != null) { Message = "Tạo mới thú cưng thành công"; _thuCungService.SaveChange(); } else { throw new DbEntityValidationException("tạo thú cưng không thành công"); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, modelThuCung)); }
public void Update(ThuCung thuCung) { _thuCungRepository.Update(thuCung); }
public ThuCung Add(ThuCung thuCung) { return(_thuCungRepository.Add(thuCung)); }