예제 #1
0
        public async Task <JsonResult> UpdateRoleForOrganization(DepartmentRole departmentRole)
        {
            var errors = departmentRole.VerifyRoleData();

            if (errors.Length != 0)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Data = errors
                }));
            }

            var dbDepartmentRole = await _departmentRoleService.GetDepartmentRoleById(departmentRole.Id);

            if (dbDepartmentRole == null)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while getting data."
                }));
            }

            dbDepartmentRole.UpdateDataBy(departmentRole);

            var saveResult = await _departmentRoleService.UpdateDepartmentRole(departmentRole);

            return(!saveResult.HasValue || !saveResult.Value
                ? new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while saving data."
            })
                : new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Success
            }));
        }
예제 #2
0
        public async Task <JsonResult> AddNewRoleForOrganization(DepartmentRole newRole)
        {
            var errors = newRole.VerifyRoleData();

            if (errors.Length != 0)
            {
                return(new JsonResult(new JsonResponse {
                    Result = SharedEnums.RequestResults.Failed, Data = errors
                }));
            }

            var saveResult = await _departmentRoleService.InsertNewDepartmentRole(newRole);

            return(!saveResult.HasValue || saveResult.Value < 1
                ? new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while saving data."
            })
                : new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Success, Data = saveResult.Value
            }));
        }