public async Task <IActionResult> Edit(string id, [Bind("MaLoai,TenLoai")] LoaiSp loaiSp) { if (id != loaiSp.MaLoai) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(loaiSp); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LoaiSpExists(loaiSp.MaLoai)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(loaiSp)); }
//Delete Loại Sản Phẩm public bool DeleteLoaiSanPham(LoaiSp lsp) { bool isCheck = false; try { OpenConnection(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandText = "sp_DELETE_LOAISP"; sqlCommand.Connection = conn; sqlCommand.Parameters.Add("@MALOAI", SqlDbType.Int).Value = lsp.MaLoai; int result = sqlCommand.ExecuteNonQuery(); if (result > 0) { isCheck = true; } return(isCheck); } catch { throw; } finally { CloseConnection(); } }
public async Task <ActionResult <LoaiSp> > PostLoaiSp(int idTH, LoaiSp loaiSp) { loaiSp.IdThuongHieu = idTH; _context.LoaiSps.Add(loaiSp); await _context.SaveChangesAsync(); return(CreatedAtAction("GetLoaiSp", new { id = loaiSp.Id }, loaiSp)); }
public async Task <IActionResult> Create([Bind("MaLoai,TenLoai")] LoaiSp loaiSp) { if (ModelState.IsValid) { _context.Add(loaiSp); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(loaiSp)); }
// GET: Admin/LoaiSp/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LoaiSp loaiSp = db.LoaiSp.Find(id); if (loaiSp == null) { return(HttpNotFound()); } return(View(loaiSp)); }
public async Task <IActionResult> PutLoaiSp(int id, LoaiSp loaiSp) { var lsp = new LoaiSp(); var result = _context.LoaiSps.Where(th => th.Id == id).FirstOrDefault <LoaiSp>(); if (result != null && lsp != null) { result.TenLoaiSp = loaiSp.TenLoaiSp; result.MoTa = loaiSp.MoTa; _context.SaveChanges(); } return(Ok()); }
public async Task <IActionResult> PutKichCoSp(int id, KichCoSp kichCoSp) { var lsp = new LoaiSp(); var result = _context.KichCoSps.Where(th => th.Id == id).FirstOrDefault <KichCoSp>(); if (result != null && lsp != null) { result.TenKichCo = kichCoSp.TenKichCo; result.GiaSp = kichCoSp.GiaSp; result.IdSanPham = kichCoSp.IdSanPham; _context.SaveChanges(); } return(Ok()); }
public ActionResult Edit([Bind(Include = "MaLoai,TenLoai,Anh")] LoaiSp loaiSp) { if (ModelState.IsValid) { if ((db.LoaiSp.Any(k => k.TenLoai == loaiSp.TenLoai)) && (db.LoaiSp.Any(k => k.MaLoai != loaiSp.MaLoai))) { ViewBag.ThongBao = "Loại sản phẩm đã tồn tại"; } else { db.Entry(loaiSp).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(loaiSp)); }
public ActionResult Create([Bind(Include = "MaLoai,TenLoai,Anh")] LoaiSp loaiSp) { if (ModelState.IsValid) { if (db.LoaiSp.Any(k => k.TenLoai == loaiSp.TenLoai)) { ViewBag.ThongBao = "Loại sản phẩm đã tồn tại"; } else { db.LoaiSp.Add(loaiSp); db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(loaiSp)); }
// Tim Kiem Loai San Pham public List <LoaiSp> TimKiemLoaiSanPham(LoaiSp lsp) { try { OpenConnection(); List <LoaiSp> lsplist = new List <LoaiSp>(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandText = "sp_TimKiemLoaiSanPham"; sqlCommand.Connection = conn; sqlCommand.Parameters.Add("@Search", SqlDbType.NVarChar).Value = lsp.Search; SqlDataReader sqlReader = sqlCommand.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(sqlReader); for (int i = 0; i < dt.Rows.Count; i++) { LoaiSp lsps = new LoaiSp(); lsps.MaLoai = int.Parse(dt.Rows[i][0].ToString()); lsps.TenLoai = dt.Rows[i][1].ToString(); lsps.Dvt = dt.Rows[i][2].ToString(); lsplist.Add(lsps); } sqlReader.Close(); return(lsplist); } catch { throw; } finally { CloseConnection(); } }
public bool ThemLoaiSanPham(LoaiSp lsp) { bool loaispCheck = false; OpenConnection(); SqlCommand command = new SqlCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = "sp_Insert_LOAISP"; command.Connection = conn; command.Parameters.Add("@TENLOAI", SqlDbType.NVarChar).Value = lsp.TenLoai; command.Parameters.Add("@DVT", SqlDbType.NChar).Value = lsp.Dvt; int result = command.ExecuteNonQuery(); if (result > 0) { loaispCheck = true; } return(loaispCheck); }
public List <LoaiSp> GetAllListLoaiSp() { try { OpenConnection(); List <LoaiSp> lsplist = new List <LoaiSp>(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandType = CommandType.Text; sqlCommand.CommandText = "SELECT *FROM dbo.LOAISP"; sqlCommand.Connection = conn; SqlDataReader sqlReader = sqlCommand.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(sqlReader); for (int i = 0; i < dt.Rows.Count; i++) { LoaiSp lsp = new LoaiSp(); lsp.MaLoai = int.Parse(dt.Rows[i][0].ToString()); lsp.TenLoai = dt.Rows[i][1].ToString(); lsp.Dvt = dt.Rows[i][2].ToString(); lsplist.Add(lsp); } sqlReader.Close(); return(lsplist); } catch { throw; } finally { CloseConnection(); } }
// Load Danh Sach Loai San Pham public List <LoaiSp> LocDanhSachLoaiSanPham(LoaiSp lsp) { return(loaiSanPhamAccess.LoadDanhSachLoaiSanPham(lsp)); }
// Tim Kiem Loai San Pham public List <LoaiSp> TimKiemLoaiSanPham(LoaiSp lsp) { return(loaiSanPhamAccess.TimKiemLoaiSanPham(lsp)); }
public bool DeleteLoaiSanPham(LoaiSp lsp) { return(loaiSanPhamAccess.DeleteLoaiSanPham(lsp)); }
public bool EditLoaiSanPham(LoaiSp lsp) { return(loaiSanPhamAccess.SuaLoaiSanPham(lsp)); }
public bool InserLoaiSanPham(LoaiSp lsp) { return(loaiSanPhamAccess.ThemLoaiSanPham(lsp)); }
// Load Danh Loai San Pham public List <LoaiSp> LoadDanhSachLoaiSanPham(LoaiSp lsp) { try { OpenConnection(); List <LoaiSp> lsplist = new List <LoaiSp>(); SqlCommand sqlCommand = new SqlCommand(); SqlDataReader sqlReader = null; DataTable dt = new DataTable(); if (lsp.Search == "Mã Loại") { sqlCommand.CommandType = CommandType.Text; sqlCommand.CommandText = "SELECT MALOAI FROM dbo.LOAISP"; sqlCommand.Connection = conn; sqlReader = sqlCommand.ExecuteReader(); dt.Load(sqlReader); for (int i = 0; i < dt.Rows.Count; i++) { LoaiSp lsps = new LoaiSp(); lsps.MaLoai = int.Parse(dt.Rows[i][0].ToString()); lsplist.Add(lsps); } } else if (lsp.Search == "Tên Loại") { sqlCommand.CommandText = "SELECT TENLOAI FROM dbo.LOAISP"; sqlCommand.Connection = conn; sqlReader = sqlCommand.ExecuteReader(); dt.Load(sqlReader); for (int i = 0; i < dt.Rows.Count; i++) { LoaiSp lsps = new LoaiSp(); lsps.TenLoai = dt.Rows[i][0].ToString(); lsplist.Add(lsps); } } else if (lsp.Search == "Đơn Vị Tính") { sqlCommand.CommandText = "SELECT DISTINCT(DVT) FROM dbo.LOAISP"; sqlCommand.Connection = conn; sqlReader = sqlCommand.ExecuteReader(); dt.Load(sqlReader); for (int i = 0; i < dt.Rows.Count; i++) { LoaiSp lsps = new LoaiSp(); lsps.Dvt = dt.Rows[i][0].ToString(); lsplist.Add(lsps); } } sqlReader.Close(); return(lsplist); } catch { throw; } finally { CloseConnection(); } }