示例#1
0
        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));
        }
示例#2
0
        public ActionResult DeleteConfirmed(int id)
        {
            ThuCung thuCung = db.ThuCungs.Find(id);

            db.ThuCungs.Remove(thuCung);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#3
0
        public ActionResult Index(int ID)
        {
            ThuCung pet = db.ThuCungs.Find(ID);

            if (pet == null)
            {
                return(View("Error"));
            }
            return(View(pet));
        }
示例#4
0
        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)));
        }
示例#5
0
        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));
        }
示例#6
0
        // 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"));
        }
示例#8
0
        // 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));
        }
示例#9
0
        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));
        }
示例#10
0
 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));
 }
示例#11
0
        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));
        }
示例#12
0
        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));
        }
示例#13
0
        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));
        }
示例#14
0
 public void Update(ThuCung thuCung)
 {
     _thuCungRepository.Update(thuCung);
 }
示例#15
0
 public ThuCung Add(ThuCung thuCung)
 {
     return(_thuCungRepository.Add(thuCung));
 }