public async Task <ActionResult> CreateOrUpdate(string userId, string[] array, DateTime ngayTra) { var muontra = new MuonTra(); var autoList = AutoCompleteTextHoSos(_taiLieuVanBanService.Gets(p => p.TrangThai == true, p => p.OrderBy(x => x.Ten)).ToList()); var users = await _userService.GetAllAsync(); var muonTras = new List <MuonTra>(); var model = Users(users, muonTras); muontra.UserId = model.FirstOrDefault(m => m.UserName == userId).Id; muontra.VanThu = User.Identity.GetUserName(); muontra.NgayMuon = DateTime.Now; muontra.NgayKetThuc = ngayTra; muontra.TinhTrang = EnumTinhTrang.DangMuon; _muonTraService.Insert(muontra); for (int i = 0; i < array.Length; i++) { var chitietmuontra = new ChiTietMuonTra(); var b = array[i]; var a = autoList.FirstOrDefault(p => p.Text == b).Id; chitietmuontra.TaiLieuVanBanId = a; chitietmuontra.MuonTraID = muontra.Id; _chiTietMuonTraService.Insert(chitietmuontra); var chiTietMuonTras = _chiTietMuonTraService.GetAll(); muontra.SoLuong = chiTietMuonTras.Count(m => m.MuonTraID == muontra.Id); _muonTraService.Update(muontra); var vanBan = _taiLieuVanBanService.Get(m => m.Id == a); vanBan.TinhTrang = EnumTinhTrang.DangMuon; _taiLieuVanBanService.Update(vanBan); } TempData["AlertMessage"] = "Tạo Mới Thành Công"; return(RedirectToAction("Index")); }
public void GiveBackOneOrTwo(List <ChiTietMuonTraViewModel> chiTietMuons) { if (chiTietMuons.Count() <= 0) { return; } string muontraId = ""; var muontraNew = new MuonTra { Id = Guid.NewGuid().ToString(), VanThu = User.Identity.GetUserName(), }; var chiTietMuonTras = new List <ChiTietMuonTra>(); foreach (var item in chiTietMuons) { var ctmt = _chiTietMuonTraService.GetById(item.Id); muontraId = item.MuonTraId; if (item.Checkbox) { ctmt.TrangThai = false; UpdateVanBan(ctmt.TaiLieuVanBanId); var chtmtNew = new ChiTietMuonTra { Id = Guid.NewGuid().ToString(), MuonTraID = muontraNew.Id, TaiLieuVanBanId = item.TaiLieuVanBanId, NgayTao = DateTime.Now, TrangThai = true }; chiTietMuonTras.Add(chtmtNew); } } var muonTraOld = _muonTraService.GetById(muontraId); _muonTraService.Update(muonTraOld); muontraNew.UserId = muonTraOld.UserId; muontraNew.NgayMuon = muonTraOld.NgayMuon; muontraNew.NgayKetThuc = muonTraOld.NgayKetThuc; muontraNew.SoLuong = chiTietMuons.Count(m => m.Checkbox == true); _muonTraService.Insert(muontraNew); _chiTietMuonTraService.Insert(chiTietMuonTras); UpdateMuonTra(muontraNew.Id); }