Exemple #1
0
        public async Task <IActionResult> UpdateBranchAsync(int id, [FromBody] BranchModelRq model)
        {
            if (!ModelState.IsValid)
            {
                Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection modelErrors = new Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection();
                foreach (var entry in ModelState.Values)
                {
                    foreach (var error in entry.Errors)
                    {
                        modelErrors.Add(error);
                    }
                }
                return(BadRequest(modelErrors));
            }
            var issuer = GetCurrentUserIdentity <int>();

            try
            {
                return(Ok(await _branchService.UpdateBranchAsync(id, model, issuer)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public async Task <IActionResult> CreateDepartmentAsync([FromBody] DepartmentModelRq model)
        {
            if (!ModelState.IsValid)
            {
                Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection modelErrors = new Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection();
                foreach (var entry in ModelState.Values)
                {
                    foreach (var error in entry.Errors)
                    {
                        modelErrors.Add(error);
                    }
                }
                return(BadRequest(modelErrors));
            }
            var issuer = GetCurrentUserIdentity <int>();

            try
            {
                if (await _departmentService.CheckCodeExistsAsync(model.Code))
                {
                    return(BadRequest("Code Exists"));
                }
                return(Ok(await _departmentService.CreateDepartmentAsync(model, issuer)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemple #3
0
 public async Task <IActionResult> AddRolesToUser([FromBody] AddRolesToUserModelRq models)
 {
     if (!ModelState.IsValid)
     {
         Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection modelErrors = new Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection();
         foreach (var entry in ModelState.Values)
         {
             foreach (var error in entry.Errors)
             {
                 modelErrors.Add(error);
             }
         }
         return(BadRequest(modelErrors));
     }
     return(OkValueObject(await _userService.AddRolesToUser(models)));
 }
Exemple #4
0
        public async Task <IActionResult> UpdateUserAsync(int id, [FromBody] UpdatedUserRq model)
        {
            if (!ModelState.IsValid)
            {
                Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection modelErrors = new Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection();
                foreach (var entry in ModelState.Values)
                {
                    foreach (var error in entry.Errors)
                    {
                        modelErrors.Add(error);
                    }
                }
                return(BadRequest(modelErrors));
            }
            var userId = await _userService.UpdateUserAsync(id, model, GetCurrentUserIdentity <int>());

            return(OkValueObject(userId));
        }
Exemple #5
0
 public async Task <IActionResult> FarmerSignUpAsync([FromBody] CreatedFarmerRq model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection modelErrors = new Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection();
             foreach (var entry in ModelState.Values)
             {
                 foreach (var error in entry.Errors)
                 {
                     modelErrors.Add(error);
                 }
             }
             return(BadRequest(modelErrors));
         }
         return(Ok(await _userService.FarmerSignUpAsync(model)));
     }
     catch (Exception exception)
     {
         return(BadRequest(exception.Message));
     }
 }