Beispiel #1
0
        public ActionResult CreateOrUpdate(KeViewModel model)
        {
            var ke = string.IsNullOrEmpty(model.Id) ? new Ke {
                NgayCapNhat = DateTime.Now
            }
                : _keService.Get(m => m.Id == model.Id);

            ViewBag.Tus = SelectListItemFromDomain.SelectListItem_Tu(_tuService.GetAll(m => m.OrderBy(t => t.Ten)));

            var checkName = _keService.Get(m => m.Ten == model.Ten);

            if (checkName != null)
            {
                TempData["AlertMessage"] = "Kệ Có Cùng Tên Đã Tồn Tại";
                return(View(model));
            }

            var userId = User.Identity.GetUserId();
            var cthd   = "kệ: " + model.Ten;

            ke.Ten        = model.Ten;
            ke.SoThuTu    = model.SoThuTu;
            ke.SoHopToiDa = model.SoHopToiDa;
            ke.NamBatDau  = model.NamBatDau;
            ke.NamKetThuc = model.NamKetThuc;
            ke.TinhTrang  = model.TinhTrang;
            ke.UserId     = User.Identity.GetUserId();
            ke.Tuid       = model.Tuid;

            if (string.IsNullOrEmpty(model.Id))
            {
                ke.SoHopHienTai = 0;

                var result = UpdateTu_SoLuongHienTai(model.Tuid, ActionWithObject.Update);
                if (!result)
                {
                    TempData["AlertMessage"] = "Số Lượng Kệ Trong Tủ Bạn Chọn Đã Đầy";
                    return(View(model));
                }
                _keService.Insert(ke);

                _functionLichSuHoatDongService.Create(ActionWithObject.Create, userId, cthd);
                TempData["AlertMessage"] = "Tạo Mới Thành Công";
            }
            else
            {
                _keService.Update(ke);
                _functionLichSuHoatDongService.Create(ActionWithObject.Update, userId, cthd);
                TempData["AlertMessage"] = "Cập Nhật Thành Công";
            }
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public ActionResult CreateOrUpdate(string id)
        {
            var model = new KeViewModel();

            ViewBag.Tus = SelectListItemFromDomain.SelectListItem_Tu(_tuService.GetAll(m => m.OrderBy(t => t.Ten)));

            if (string.IsNullOrEmpty(id))
            {
                return(View(model));
            }
            else
            {
                var ke = _keService.Get(m => m.Id == id);
                model = GetKe(ke);
                return(View(model));
            }
        }
Beispiel #3
0
        private KeViewModel GetKe(Ke x)
        {
            var model = new KeViewModel
            {
                Id           = x.Id,
                Ten          = x.Ten,
                SoHopToiDa   = x.SoHopToiDa,
                SoHopHienTai = x.SoHopHienTai,
                NamBatDau    = x.NamBatDau,
                NamKetThuc   = x.NamKetThuc,
                SoThuTu      = x.SoThuTu,
                TinhTrang    = x.TinhTrang,
                NgayTao      = x.NgayTao,
                NgayCapNhat  = x.NgayCapNhat,
                TrangThai    = x.TrangThai,
                UserId       = x.UserId,
                Tuid         = x.Tuid,
                Hops         = x.Hops,
                User         = x.User,
                Tu           = x.Tu
            };

            return(model);
        }