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"));
        }
Example #2
0
        private List <MuonTraViewModel> GetMuonTras(IList <MuonTra> muontras)
        {
            var chiTietMuonTras = _chiTietMuonTraService.GetAll();

            return(muontras.Select(x => new MuonTraViewModel
            {
                Id = x.Id,
                NgayMuon = x.NgayMuon,
                NgayTra = x.NgayKetThuc,
                NgayCapNhat = x.NgayCapNhat,
                TinhTrang = x.TinhTrang,
                TrangThai = x.TrangThai,
                VanThu = x.VanThu,
                UserId = x.UserId,
                User = x.User,
                SoLuong = x.SoLuong,
                ChiTietMuonTras = chiTietMuonTras,
            }).ToList());
        }
        public IHttpActionResult GetAll()
        {
            var list = _chiTietMuonTraService.GetAll().ToList().Select(Mapper.Map <ChiTietMuonTra, ChiTietMuonTraDto>);

            return(Ok(list));
        }