private HoSoViewModel GetHoSo(HoSo x)
        {
            var autoList = LocalHops(GetHops());

            var model = new HoSoViewModel
            {
                Id              = x.Id,
                BienMucHoSo     = x.BienMucHoSo,
                GhiChu          = x.GhiChu,
                PhongLuuTru     = x.PhongLuuTru,
                LoaiHoSo        = x.LoaiHoSo,
                HoSoCons        = x.HoSoCons,
                TapHoSo         = x.TapHoSo,
                TinhTrang       = x.TinhTrang,
                ThoiGianBaoQuan = x.ThoiGianBaoQuan,
                User            = x.User,
                TaiLieuVanBans  = x.TaiLieuVanBans,
                NgayTao         = x.NgayTao,
                NgayCapNhat     = x.NgayCapNhat,
                TrangThai       = x.TrangThai,
                Hop             = x.Hop,
                HopId           = autoList.FirstOrDefault(p => p.Id == x.HopId).Text,
                LoaiHoSoId      = x.LoaiHoSoId,
                TapHoSoId       = x.TapHoSoId,
                UserId          = x.UserId
            };

            return(model);
        }
        public ActionResult CreateOrUpdate(HoSoViewModel model)
        {
            var hoSo = string.IsNullOrEmpty(model.Id) ? new HoSo {
                NgayCapNhat = DateTime.Now
            }
                : _hoSoService.Get(m => m.Id == model.Id);

            ViewBag.LoaiHoSos = SelectListItemFromDomain.SelectListItem_LoaiHoSo(_loaiHoSoService.GetAll(m => m.OrderBy(t => t.Ten)));
            ViewBag.TapHoSos  = SelectListItemFromDomain.SelectListItem_HoSo(_hoSoService.GetAll(m => m.OrderBy(t => t.PhongLuuTru)));

            var checkName = _hoSoService.Get(m => m.PhongLuuTru == model.PhongLuuTru);

            if (checkName != null)
            {
                TempData["AlertMessage"] = "Hồ Sơ Có Cùng Phông Lưu Trữ Đã Tồn Tại";
                return(View(model));
            }

            var autoList        = LocalHops(GetHops());
            var userId          = User.Identity.GetUserId();
            var chiTietHoatDong = "hồ sơ: " + model.PhongLuuTru;

            hoSo.TapHoSoId       = model.TapHoSoId;
            hoSo.PhongLuuTru     = model.PhongLuuTru;
            hoSo.TinhTrang       = EnumTinhTrang.TrongKho;
            hoSo.ThoiGianBaoQuan = model.ThoiGianBaoQuan;
            hoSo.GhiChu          = model.GhiChu;
            hoSo.BienMucHoSo     = model.BienMucHoSo;
            hoSo.LoaiHoSoId      = model.LoaiHoSoId;
            hoSo.HopId           = autoList.FirstOrDefault(p => p.Text == model.HopId).Id;
            hoSo.UserId          = userId;

            if (string.IsNullOrEmpty(model.Id))
            {
                _hoSoService.Insert(hoSo);
                _functionLichSuHoatDongService.Create(ActionWithObject.Create, userId, chiTietHoatDong);
                TempData["AlertMessage"] = "Tạo Mới Thành Công";
            }
            else
            {
                _hoSoService.Update(hoSo);
                _functionLichSuHoatDongService.Create(ActionWithObject.Update, userId, chiTietHoatDong);
                TempData["AlertMessage"] = "Cập Nhật Thành Công";
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult CreateOrUpdate(string id)
        {
            var model = new HoSoViewModel();

            ViewBag.LoaiHoSos = SelectListItemFromDomain.SelectListItem_LoaiHoSo(_loaiHoSoService.GetAll(m => m.OrderBy(t => t.Ten)));
            ViewBag.TapHoSos  = SelectListItemFromDomain.SelectListItem_HoSo(_hoSoService.GetAll(m => m.OrderBy(t => t.PhongLuuTru)));

            if (string.IsNullOrEmpty(id))
            {
                return(View(model));
            }
            else
            {
                var hoSo = _hoSoService.Get(m => m.Id == id);
                model = GetHoSo(hoSo);
                return(View(model));
            }
        }