public async Task <IActionResult> Edit(DefaultModel model, ModGradeEntity item)
        {
            ViewBag.Title = "Cập nhật thông tin";
            if (string.IsNullOrEmpty(model.ID) && string.IsNullOrEmpty(item.ID))
            {
                SetMessageWarning("Chưa chọn đối tượng chỉnh sửa");
            }
            else
            {
                string ID    = !string.IsNullOrEmpty(model.ID) ? model.ID : item.ID;
                var    _item = _service.GetByID(ID);
                if (!string.IsNullOrEmpty(item.Name))
                {
                    _item.Name = item.Name;
                }
                _item.Updated = DateTime.Now;
                //TODO: tính toán xem có cần cập nhật lại code ko
                _item.ParentID = item.ParentID;
                _item.IsActive = item.IsActive;
                await _service.AddAsync(_item);

                ViewBag.Root = _service.GetRootItems();
                ViewBag.Data = _service.GetByID(ID);
                SetMessageSuccess("Cập nhật thành công");
            }
            ViewBag.Model = model;
            return(RedirectToAction("index"));
        }
예제 #2
0
        public async Task <IActionResult> Edit(DefaultModel model, ModGradeEntity item)
        {
            ViewBag.Title = "Chỉnh sửa";
            if (string.IsNullOrEmpty(model.ID) && string.IsNullOrEmpty(item.ID))
            {
                ViewBag.Message = "Chưa chọn đối tượng đê sửa";
            }
            else
            {
                string ID    = !string.IsNullOrEmpty(model.ID) ? model.ID : item.ID;
                var    _item = _service.GetByID(ID);
                item.ID = _item.ID;
                if (string.IsNullOrEmpty(item.Name))
                {
                    item.Name = _item.Name;
                }
                if (string.IsNullOrEmpty(item.Code))
                {
                    item.Code = UnicodeName.ConvertUnicodeToCode(item.Name, "-", true);
                }
                await _service.AddAsync(item);

                ViewBag.Data = _service.GetByID(ID);
            }
            ViewBag.Model = model;
            return(RedirectToAction("index"));
        }
예제 #3
0
        public async Task <IActionResult> Create(DefaultModel model, ModGradeEntity item)
        {
            ViewBag.Title = "Thêm mới";
            if (!string.IsNullOrEmpty(model.ID) || !string.IsNullOrEmpty(item.ID))
            {
                return(RedirectToAction("Edit", new { model.ID }));
            }
            else
            {
                if (string.IsNullOrEmpty(item.Name))
                {
                    ViewBag.Message = "Bạn chưa điện tên của nhóm";
                    return(View());
                }
                else
                {
                    item.Code = UnicodeName.ConvertUnicodeToCode(item.Name, "-", true);

                    if (_service.GetItemByCode(item.Code) == null)
                    {
                        await _service.AddAsync(item);

                        ViewBag.Message = "Thêm thành công";
                    }
                    else
                    {
                        ViewBag.Message = "Nhóm người đã tồn tại";
                        return(View());
                    }
                }
            }
            return(View());
        }
예제 #4
0
 public ModGradeViewModel(ModGradeEntity entity)
 {
     ID            = entity.ID;
     ParentID      = entity.ParentID;
     IsActive      = entity.IsActive;
     Code          = entity.Code;
     CreateUser    = entity.CreateUser;
     Name          = entity.Name;
     SubGradeCount = 0;
     Parent        = null;
     Created       = entity.Created;
     Updated       = entity.Updated;
 }
        public async Task <IActionResult> Create(DefaultModel model, ModGradeEntity item)
        {
            ViewBag.Title = "Thêm mới";

            if (!string.IsNullOrEmpty(model.ID) || !string.IsNullOrEmpty(item.ID))
            {
                return(RedirectToAction("Edit", new { model.ID }));
            }
            else
            {
                if (string.IsNullOrEmpty(item.Name))
                {
                    SetMessageWarning("Bạn chưa điền tên của cấp độ");
                    return(View());
                }
                else
                {
                    item.Code       = UnicodeName.ConvertUnicodeToCode(item.Name, "-", true);
                    item.Created    = DateTime.Now;
                    item.Updated    = DateTime.Now;
                    item.IsAdmin    = true;
                    item.CreateUser = _currentUser.ID;
                    if (_service.GetItemByCode(item.Code) == null)
                    {
                        await _service.AddAsync(item);

                        SetMessageSuccess("Thêm mới thành công");
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        SetMessageWarning("Cấp độ đã tồn tại!");
                        ViewBag.Root = _service.GetRootItems();
                        return(View());
                    }
                }
            }
        }