private HopViewModel GetHop(Hop hop)
        {
            var autoList = AutoCompleteTextKes(GetKes());

            var model = new HopViewModel
            {
                Id          = hop.Id,
                ChuyenDe    = hop.ChuyenDe,
                NgayBatDau  = hop.NgayBatDau,
                NgayKetThuc = hop.NgayKetThuc,
                PhongBan    = hop.PhongBan,
                SoHop       = hop.SoHop,
                PhongBanId  = hop.PhongBanId,
                TinhTrang   = hop.TinhTrang,
                NgayTao     = hop.NgayTao,
                NgayCapNhat = hop.NgayCapNhat,
                TrangThai   = hop.TrangThai,
                UserId      = hop.UserId,
                HoSos       = hop.HoSos,
                Ke          = hop.Ke,
                User        = hop.User,
                KeId        = autoList.FirstOrDefault(p => p.Id == hop.KeId).Text
            };

            return(model);
        }
Exemplo n.º 2
0
        public ActionResult HopList()
        {
            var hops      = db.hops.ToList();
            var viewModel = new HopViewModel {
                HopList = hops
            };

            return(View(viewModel));
        }
Exemplo n.º 3
0
        public ActionResult CreateOrUpdate(HopViewModel model)
        {
            var hop = string.IsNullOrEmpty(model.Id) ? new Hop {
                NgayCapNhat = DateTime.Now
            }
                : _hopService.Get(m => m.Id == model.Id);

            var    autoList        = AutoCompleteTextKes(GetKes());
            string userId          = User.Identity.GetUserId();
            string chiTietHoatDong = "hộp: " + hop.ChuyenDe;

            hop.ChuyenDe    = model.ChuyenDe;
            hop.KeId        = autoList.FirstOrDefault(p => p.Text == model.KeId).Id;
            hop.PhongBanId  = model.PhongBanId;
            hop.SoHop       = model.SoHop;
            hop.UserId      = userId;
            hop.NgayBatDau  = model.NgayBatDau;
            hop.NgayKetThuc = model.NgayKetThuc;

            // create new
            if (string.IsNullOrEmpty(model.Id))
            {
                DropDownList();

                var checkName = _hopService.Get(m => m.ChuyenDe == model.ChuyenDe);

                // check name
                if (checkName != null)
                {
                    TempData["AlertMessage"] = "Hộp Chuyên Đề Đã Tồn Tại";
                    return(View(model));
                }

                hop.TinhTrang = EnumTinhTrang.TrongKho;
                var result = UpdateTu_SoHopHienTai(hop.KeId, ActionWithObject.Update);

                // check amout ke
                if (!result)
                {
                    TempData["AlertMessage"] = "Số Lượng Hộp Trong Kệ Bạn Chọn Đã Đầy";
                    return(View(model));
                }
                _hopService.Insert(hop);

                _functionLichSuHoatDongService.Create(ActionWithObject.Create, userId, chiTietHoatDong);

                TempData["AlertMessage"] = "Tạo Mới Thành Công";
            }
            else // update
            {
                _hopService.Update(hop);

                _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 HopViewModel();

            DropDownList();

            if (string.IsNullOrEmpty(id))
            {
                return(View(model));
            }
            else
            {
                var hop = _hopService.Get(m => m.Id == id);
                model = GetHop(hop);
                return(View(model));
            }
        }
Exemplo n.º 5
0
 void NewHop()
 {
     SelectedHop = new HopViewModel(new StockHop());
 }