Ejemplo n.º 1
0
        public JsonResult Action(DepartmentActionModel departmentActionModel)
        {
            JsonResult jsonResult = new JsonResult();

            if (departmentActionModel.ID > 0)
            {
                departmentActionModel.ModifiedOn = DateTimeHelper.Now();
                departmentActionModel.UserID     = UserHelperInfo.GetUserId();
                departmentActionModel.IP         = UserInfo.IP();
                departmentActionModel.Agent      = UserInfo.Agent();
                departmentActionModel.Location   = UserInfo.Location();
                var(IsSaved, Error) = departmentService.UpdateDepartment(departmentActionModel);
                jsonResult.Data     = new { Success = IsSaved, Msg = Error };
            }
            else
            {
                Department department = new Department
                {
                    Name        = departmentActionModel.Name,
                    Description = departmentActionModel.Description,
                    ModifiedOn  = DateTimeHelper.Now(),
                    UserID      = UserHelperInfo.GetUserId(),
                    IP          = UserInfo.IP(),
                    Agent       = UserInfo.Agent(),
                    Location    = UserInfo.Location()
                };
                var(IsSaved, Error) = departmentService.SaveDepartment(department);
                jsonResult.Data     = new { Success = IsSaved, Msg = Error };
            }
            return(jsonResult);
        }
Ejemplo n.º 2
0
        public ActionResult Delete(DepartmentActionModel departmentActionModel)
        {
            (bool IsTrue, string Error) = departmentService.Delete(departmentActionModel.ID);
            JsonResult jsonResult = new JsonResult
            {
                Data = new { Success = IsTrue, Msg = Error }
            };

            return(jsonResult);
        }
Ejemplo n.º 3
0
        public ActionResult Delete(int ID)
        {
            Department            department            = departmentService.GetDepartmentByID(ID);
            DepartmentActionModel departmentActionModel = new DepartmentActionModel
            {
                ID   = department.ID,
                Name = department.Name
            };

            return(PartialView("_Delete", departmentActionModel));
        }
Ejemplo n.º 4
0
        public ActionResult Action(int?ID)
        {
            DepartmentActionModel departmentActionModel = new DepartmentActionModel();

            if (ID.HasValue)
            {
                Department department = departmentService.GetDepartmentByID(ID.Value);
                departmentActionModel.ID   = department.ID;
                departmentActionModel.Name = department.Name;

                departmentActionModel.Description = department.Description;
            }
            return(PartialView("_Action", departmentActionModel));
        }
Ejemplo n.º 5
0
        public async Task <JsonResult> Action(DepartmentActionModel model)
        {
            JsonResult result = new JsonResult
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
            var  message   = "";
            bool isSuccess = false;

            try
            {
                if (ModelState.IsValid)
                {
                    if (model.ID > 0)
                    {
                        _deparment      = _IDepartmentServices.GetDataById(model.ID);
                        _deparment.Name = model.Name;
                        isSuccess       = _IDepartmentServices.UpdateData(_deparment);
                    }
                    else
                    {
                        _deparment.Name = model.Name;
                        isSuccess       = await Task.Run(() => _IDepartmentServices.SaveData(_deparment));
                    }
                }
                else
                {
                    message = string.Join("; ", ModelState.Values
                                          .SelectMany(x => x.Errors)
                                          .Select(x => x.ErrorMessage));
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            if (isSuccess)
            {
                message     = "Data Save Successfully!!";
                result.Data = new { Success = true, Message = message };
            }
            else
            {
                result.Data = new { Success = false, Message = message };
            }
            return(result);
        }