// [Audit] public ActionResult Create([Bind(Include = "MaNhomNhaCungCap,TenNhomNhaCungCap,GhiChu,MaNhaThuoc")] NhomNhaCungCap nhomNhaCungCap) { if (ModelState.IsValid) { try { var maNhaThuoc = this.GetNhaThuoc().MaNhaThuoc; var itemExist = unitOfWork.NhomNhaCungCapRepository.Get(c => c.MaNhaThuoc == maNhaThuoc && c.TenNhomNhaCungCap.Trim().Equals(nhomNhaCungCap.TenNhomNhaCungCap.Trim(), StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (itemExist != null) { ModelState.AddModelError("TenNhomNhaCungCap", "Tên nhóm nhà cung cấp này đã tồn tại. Vui lòng nhập tên nhóm nhà cung cấp khác."); } else { nhomNhaCungCap.NhaThuoc = unitOfWork.NhaThuocRepository.GetById(this.GetNhaThuoc().MaNhaThuoc); nhomNhaCungCap.Created = DateTime.Now; nhomNhaCungCap.CreatedBy = unitOfWork.UserProfileRepository.GetById(WebSecurity.GetCurrentUserId); unitOfWork.NhomNhaCungCapRepository.Insert(nhomNhaCungCap); unitOfWork.Save(); return(RedirectToAction("Index")); } } catch (Exception e) { ModelState.AddModelError("TenNhomNhaCungCap", e.Message); } } return(View(nhomNhaCungCap)); }
public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var maNhaThuoc = this.GetNhaThuoc().MaNhaThuoc; NhomNhaCungCap nhomNhaCungCap = unitOfWork.NhomNhaCungCapRepository.GetMany( e => e.MaNhomNhaCungCap == id && e.NhaThuoc.MaNhaThuoc == maNhaThuoc).First(); if (nhomNhaCungCap == null) { return(HttpNotFound()); } return(View(nhomNhaCungCap)); }
public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } NhomNhaCungCap nhomNhaCungCap = await db.NhomNhaCungCaps.FindAsync(id); if (nhomNhaCungCap == null) { return(HttpNotFound()); } if (!User.IsInRole("Admin") && nhomNhaCungCap.MaNhaThuoc != this.GetNhaThuoc().MaNhaThuoc) { throw new UnauthorizedAccessException(); } return(View(nhomNhaCungCap)); }
// [Audit] public ActionResult Edit([Bind(Include = "MaNhomNhaCungCap,TenNhomNhaCungCap,GhiChu,MaNhaThuoc")] NhomNhaCungCap nhomNhaCungCap) { if (ModelState.IsValid) { try { var maNhaThuoc = this.GetNhaThuoc().MaNhaThuoc; var itemExist = unitOfWork.NhomNhaCungCapRepository.Get(c => c.MaNhaThuoc == maNhaThuoc && c.MaNhomNhaCungCap != nhomNhaCungCap.MaNhomNhaCungCap && c.TenNhomNhaCungCap.Trim().Equals(nhomNhaCungCap.TenNhomNhaCungCap.Trim(), StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (itemExist != null) { ModelState.AddModelError("TenNhomNhaCungCap", "Tên nhóm nhà cung cấp này đã tồn tại. Vui lòng nhập tên nhóm nhà cung cấp khác."); } else { var nhom = unitOfWork.NhomNhaCungCapRepository.GetMany( e => e.MaNhomNhaCungCap == nhomNhaCungCap.MaNhomNhaCungCap && e.NhaThuoc.MaNhaThuoc == maNhaThuoc).First(); if (Constants.Default.ConstantEntities.NhomNhaCungCaps.Contains(nhom.TenNhomNhaCungCap)) { ModelState.AddModelError("TenNhomNhaCungCap", "Không thể sửa tên nhóm nhà cung cấp mặc định + " + nhom.TenNhomNhaCungCap); } else { nhom.TenNhomNhaCungCap = nhomNhaCungCap.TenNhomNhaCungCap; nhom.GhiChu = nhomNhaCungCap.GhiChu; nhom.Modified = DateTime.Now; nhom.ModifiedBy = unitOfWork.UserProfileRepository.GetById(WebSecurity.GetCurrentUserId); unitOfWork.NhomNhaCungCapRepository.Update(nhom); unitOfWork.Save(); return(RedirectToAction("Index")); } } } catch (Exception e) { ModelState.AddModelError("TenNhomNhaCungCap", e.Message); } } return(View(nhomNhaCungCap)); }
private NhaCungCap BindNhaCungCap(ref NhaCungCap nhacungcap, Excel.Row row) { var maNhaThuoc = this.GetNhaThuoc().MaNhaThuoc; //Nhom nha cung cap var tennhomnhacungcap = sThuoc.Utils.Helpers.RemoveEncoding(row.Cells[0].Text.Trim()); var nhomnhacungcap = unitOfWork.NhomNhaCungCapRepository.GetMany(x => x.MaNhaThuoc == maNhaThuoc && x.TenNhomNhaCungCap == tennhomnhacungcap).FirstOrDefault(); if (nhomnhacungcap == null && !String.IsNullOrEmpty(tennhomnhacungcap)) { nhomnhacungcap = new NhomNhaCungCap { TenNhomNhaCungCap = tennhomnhacungcap, NhaThuoc = unitOfWork.NhaThuocRepository.GetById(maNhaThuoc), MaNhomNhaCungCap = 0, GhiChu = "", CreatedBy = unitOfWork.UserProfileRepository.GetById(WebSecurity.GetCurrentUserId), Created = DateTime.Now }; unitOfWork.NhomNhaCungCapRepository.Insert(nhomnhacungcap); unitOfWork.Save(); } if (nhomnhacungcap != null) { nhacungcap.NhomNhaCungCap = nhomnhacungcap; } // //Bindding Cac thong tin // var tennhacungcap = row.Cells[1].Text.Trim(); if (!String.IsNullOrWhiteSpace(tennhacungcap)) { nhacungcap.TenNhaCungCap = tennhacungcap; } // var sodienthoai = row.Cells[3] != null ? row.Cells[3].Text.Trim() : string.Empty; if (!String.IsNullOrWhiteSpace(sodienthoai)) { nhacungcap.SoDienThoai = sodienthoai; } // var diachi = row.Cells[2] != null ? row.Cells[2].Text.Trim() : string.Empty; if (!String.IsNullOrWhiteSpace(diachi)) { nhacungcap.DiaChi = diachi; } // var nodauky = (row.Cells[4] != null && !string.IsNullOrEmpty(row.Cells[4].Text.Trim())) ? Convert.ToDecimal(row.Cells[4].Value.Trim()) : 0; nhacungcap.NoDauKy = nodauky; // var sofax = row.Cells[5] != null ? row.Cells[5].Text.Trim() : string.Empty; if (!String.IsNullOrWhiteSpace(sofax)) { nhacungcap.SoFax = sofax; } // var masothue = row.Cells[6] != null ? row.Cells[6].Text.Trim() : string.Empty; if (!String.IsNullOrWhiteSpace(masothue)) { nhacungcap.MaSoThue = masothue; } // var nguoidaidien = row.Cells[7] != null ? row.Cells[7].Text.Trim() : string.Empty; if (!String.IsNullOrWhiteSpace(nguoidaidien)) { nhacungcap.NguoiDaiDien = nguoidaidien; } // var nguoilienhe = row.Cells[8] != null ? row.Cells[8].Text.Trim() : string.Empty; if (!String.IsNullOrWhiteSpace(nguoilienhe)) { nhacungcap.NguoiLienHe = nguoilienhe; } // var email = row.Cells[9] != null ? row.Cells[9].Text.Trim() : string.Empty; if (!String.IsNullOrWhiteSpace(email)) { nhacungcap.Email = email; } return(nhacungcap); }