Beispiel #1
0
        public async Task <IActionResult> AddNewClient([FromBody] UpdateClientViewModal command)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(new { Success = false, Message = "Parameter can not be null" }));
                }

                string EmployerId = "";
                if (command.ClientId == null)
                {
                    //add client
                    command.Email = command.Email.ToLower();

                    //check if username is unique
                    bool isUniqueEmail = await _authenticationService.UniqueEmail(command.Email);

                    if (!isUniqueEmail)
                    {
                        return(Json(new { Success = false, Message = "This email is currently in use" }));
                    }

                    EmployerId = await _authenticationService.AddEmployer(command);

                    var newClient = (await _authenticationService.AddEmployerAsClientAsync(EmployerId, _userAppContext.CurrentUserId));

                    return(Json(new { Success = true, Message = "Successful", newClient }));
                }
                return(Json(new { Success = false, Message = "OOPS! Something Went Wrong" }));
            }
            catch (ApplicationException e)
            {
                return(Json(new { IsSuccess = false, e.Message }));
            }
        }