예제 #1
0
        public IActionResult UpdateDepartment([FromBody] DepartmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var result = ManageSiteHelper.AddDepartment(model, _context);

                    if (result == UpdateResult.Error)
                    {
                        throw new Exception("Department couldn't be updated.");
                    }
                    else if (result == UpdateResult.Duplicate)
                    {
                        throw new Exception("Department already exists.");
                    }

                    return(ControllerHelper.ReturnResult(UpdateResult.Success));
                }
                catch (Exception ex)
                {
                    StatusMessage = "An Error occured; " + ex.Message;
                }
            }

            model.StatusMessage = StatusMessage;

            return(ControllerHelper.ReturnResult(UpdateResult.Error, StatusMessage));
        }
        public IActionResult Department(DepartmentViewModel model)
        {
            string failureMessage = null;
            string successMessage = null;
            var    redirectUrl    = "/ManageSite/Department";

            if (ModelState.IsValid)
            {
                var result = ManageSiteHelper.AddDepartment(model, _context);


                if (result == UpdateResult.Error)
                {
                    failureMessage = "Department couldn't be updated.";
                }
                else if (result == UpdateResult.Success)
                {
                    successMessage = "Department updated.";
                }
                else if (result == UpdateResult.Duplicate)
                {
                    failureMessage = "Department already exists.";
                }
            }

            if (!string.IsNullOrWhiteSpace(failureMessage))
            {
                redirectUrl += string.Format("?failureMessage={0}", failureMessage);
            }
            if (!string.IsNullOrWhiteSpace(successMessage))
            {
                redirectUrl += string.Format("?successMessage={0}", successMessage);
            }

            return(ControllerHelper.RedirectToLocal(this, redirectUrl));
        }