Esempio n. 1
0
        public IActionResult Post([FromBody] Employee employee)
        {
            if (!ModelState.IsValid)
            {
                _logger.AddLog(BadRequest(ModelState).ToString(), BadRequest().GetType().ToString());
                return(BadRequest(ModelState));
            }
            try
            {
                var doesExistAlready = _registerEmployee.IsEmpIdExist(employee.EmpId);
                if (doesExistAlready)
                {
                    return(StatusCode(StatusCodes.Status406NotAcceptable, "Employee ID exists"));
                }

                //Inside this post with image we are checking if this user.username (containing official email) already exists or not
                if (_registerEmployee.PostWithImage(employee) == true)
                {
                    _passwordResetService.GenerateAndSendEmail(employee.PersonalInfo.Email, employee.Username);
                    return(Ok());
                }
                return(BadRequest(ModelState));
            }
            catch (Exception E)
            {
                _logger.AddLog(E.ToString(), E.GetType().ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }