public HttpResponseMessage GetById(HttpRequestMessage request, int id) { return(CreateHttpResponse(request, () => { var sanPhamByID = _sanPhamService.GetById(id); var response = request.CreateResponse(HttpStatusCode.OK, sanPhamByID); return response; })); }
public IActionResult SanPham(string Id) { ViewBag.ListThongSoKiThuat = _thongSoKiThuatService.GetThongSoKiThuat(Id); var data = _sanPhamService.GetById(Id); return(View(data)); }
public IActionResult XoaSanPham(string Id) { //context.SanPham.Find(Id).Status = 0; //context.SaveChanges(); _spService.Delete(Id); return(RedirectToAction("QuanLy", "Admin", new { id = _spService.GetById(Id).LoaiSp /* context.SanPham.Find(Id).LoaiSp*/ }).WithSuccess("Thành công", "Bạn đã xóa sản phẩm khỏi danh sách.")); }
public HttpResponseMessage GetById(HttpRequestMessage request, int id) { SanPham sanPhamSingler = null; try { sanPhamSingler = _sanPhamService.GetById(id); if (sanPhamSingler != null) { Message = "Thông tin sản phẩm với id: " + id; } else { throw new DbEntityValidationException(string.Format("Không tìm kiếm được sản phẩm với id {0}", id)); } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, sanPhamSingler)); }
public async Task <IActionResult> Get(int id) { return(Ok(await sanPhamService.GetById(id))); }
public ActionResult CapNhat(int id) { ViewBag.LoaiSanPhamID = new SelectList(sanPham.GetAll_LoaiSp(), "ID", "TenLoai"); return(PartialView(sanPham.GetById(id))); }
public HttpResponseMessage CheckCtHoaDonAndCreareHoaDon(HttpRequestMessage request, ChiTietHoaDon[] chiTietHoaDon, int idNguoiDung) { // kiểm tra danh sách sản phẩm có bị thiếu hàng hay không var trangThai = new bool[chiTietHoaDon.Length]; var tenSanPham = new string[chiTietHoaDon.Length]; IList <SanPham> listSanPhams = new List <SanPham>(); var mess = "sản phẩm "; try { var i = 0; foreach (var item in chiTietHoaDon) { trangThai[i] = true; if (item.IdSanPham != null) { var sanPham = _sanPhamService.GetById((int)item.IdSanPham); listSanPhams.Add(sanPham); if (sanPham.SoLuong < item.SoLuong) { trangThai[i] = false; tenSanPham[i] = sanPham.TenSanPham; } } i++; } var cout = 0; for (var j = 0; j < trangThai.Length; j++) { if (trangThai[j]) { continue; } cout++; mess += tenSanPham[j] + " "; } mess += "không đủ số lượng để mua"; if (cout == 0) { // lấy ra danh sách các shop int[] mangShop = new int[listSanPhams.Count]; int k = 0; foreach (var listSanPham in listSanPhams) { if (listSanPham.IdShop != null) { mangShop[k] = (int)listSanPham.IdShop; } k++; } // gộp id shop trùng lại với nhau IList <int> mangShopSort = new List <int>(); for (int j = 0; j < mangShop.Length; j++) { int countmang = 0; foreach (var t in mangShopSort) { if (mangShop[j] == t) { countmang++; } } if (countmang == 0) { mangShopSort.Add(mangShop[j]); } } // có id shop rồi thì tạo hóa đơn tương ứng foreach (var item1 in mangShopSort) { var hoadon = new HoaDon() { IdNguoiDung = idNguoiDung, IdShop = item1, NgayLapHoaDon = DateTime.Now, TrangThai = false, }; HoaDon hoaDon = _hoaDonService.Add(hoadon); _hoaDonService.SaveChange(); double tongGia = 0; foreach (var item2 in chiTietHoaDon) { if (item2.IdSanPham != null) { var sanPham = _sanPhamService.GetById((int)item2.IdSanPham); if (sanPham.IdShop == item1) { item2.IdHoaDon = hoaDon.IdHoaDon; if (item2.Gia != null) { if (item2.SoLuong != null) { tongGia += (double)item2.Gia * (int)item2.SoLuong; } } _chiTietHoaDonService.Add(item2); _chiTietHoaDonService.SaveChange(); } } } hoaDon.TongGia = tongGia; _hoaDonService.Update(hoaDon); _hoaDonService.SaveChange(); var listCthoaDon = _chiTietHoaDonService.GetAllByIdHoaDon(hoaDon.IdHoaDon); foreach (var item in listCthoaDon) { if (item.IdSanPham == null) { continue; } var sanPham = _sanPhamService.GetById((int)item.IdSanPham); if (sanPham.SoLuong == null) { continue; } var soLuong = (int)sanPham.SoLuong; sanPham.SoLuong = soLuong - item.SoLuong; } _hoaDonService.SaveChange(); } _hoaDonService.SaveChange(); Message = "Hóa đơn được thông qua"; } else { Message = mess; IsSuccess = false; } } catch (DbEntityValidationException ex) { LogException(ex); } return(GetResponseMessage(IsSuccess, Message, 1, null)); }
/// <summary> /// Deletes the specified value. /// </summary> /// <param name="value">The value.</param> public void Delete(int value) { SanPham entity = sanPhamService.GetById(value); sanPhamService.Delete(entity); }