public IHttpActionResult CreateUser(User user) { //Validate if required securityCodeExternaRegister string securityCodeExternaRegister = ConfigurationParameter.Required_SecurityCodeExternaRegister; if (securityCodeExternaRegister.Equals("1")) { if (string.IsNullOrEmpty(user.Code)) { response.Code = InternalResponseCodeError.Code308; response.Message = InternalResponseCodeError.Message308; return(Ok(response)); } } //Validate security code bool resultValidateSecCode = UserRoleService.ValidateSecurityCode(user.Code); if (!resultValidateSecCode) { if (securityCodeExternaRegister.Equals("0")) { response.Code = InternalResponseCodeError.Code306; response.Message = InternalResponseCodeError.Message306; } else { response.Code = InternalResponseCodeError.Code307; response.Message = InternalResponseCodeError.Message307; } return(Ok(response)); } if (string.IsNullOrEmpty(user.UserName) || string.IsNullOrEmpty(user.EmailAddress) || string.IsNullOrEmpty(user.Password) || string.IsNullOrEmpty(user.Name) || string.IsNullOrEmpty(user.Surname)) { response.Message = "Los Datos ingresados no son validos"; response.Code = "007"; } var validateUserName = userService.ValidateUserName(user.UserName); if (validateUserName.UserNameExist) { response.Message = "El nombre de usuario que desea registrar ya existe"; response.Code = "001"; return(Ok(response)); } string StatusExternalUser = Constants.ConfigurationParameter.StatusExternalUser; var CurrentStatus = db.UserStatus.Where(x => x.ShortName == StatusExternalUser).FirstOrDefault(); var systemUser = db.Users.Where(x => x.UserName == "system").FirstOrDefault(); user.Password = Utilities.Security.Encrypt_OneWay(user.Password); user.StatusId = CurrentStatus.Id; user.CreationTime = DateTime.Now; user.CreatorUserId = systemUser.Id; user.IsActive = true; var UserResult = db.Users.Add(user); db.SaveChanges(); //Create rol #region Create rol bool UserRol = UserRoleService.CreateUserRol(UserResult.Id, user.Code); #endregion response.Message = "Usuario creado con exito"; return(Ok(response)); }
public IHttpActionResult CreateUser(User user) { Response response = new Response(); //Validate if required securityCodeExternaRegister string securityCodeExternaRegister = ConfigurationParameter.Required_SecurityCodeExternaRegister; if (securityCodeExternaRegister.Equals("1")) { if (string.IsNullOrEmpty(user.Code)) { response.Code = InternalResponseCodeError.Code308; response.Message = InternalResponseCodeError.Message308; return(Ok(response)); } } //Validate security code bool resultValidateSecCode = UserRoleService.ValidateSecurityCode(user.Code); if (!resultValidateSecCode) { if (securityCodeExternaRegister.Equals("0")) { response.Code = InternalResponseCodeError.Code306; response.Message = InternalResponseCodeError.Message306; } else { response.Code = InternalResponseCodeError.Code307; response.Message = InternalResponseCodeError.Message307; } return(Ok(response)); } if (string.IsNullOrEmpty(user.UserName) || string.IsNullOrEmpty(user.EmailAddress) || string.IsNullOrEmpty(user.Password) || string.IsNullOrEmpty(user.Name) || string.IsNullOrEmpty(user.Surname)) { response.Message = "Los Datos ingresados no son validos"; response.Code = "007"; } var validateUserName = db.Database.SqlQuery <ValidateUserName>( "Exec SP_ValidateUserName @UserName", new SqlParameter() { ParameterName = "@UserName", SqlDbType = System.Data.SqlDbType.Text, Value = (object)user.UserName ?? DBNull.Value } ).ToList(); if (validateUserName[0].UserNameExist) { response.Message = "El nombre de usuario que desea registrar ya existe"; response.Code = "001"; return(Ok(response)); } string StatusExternalUser = Constants.ConfigurationParameter.StatusExternalUser; var CurrentStatus = db.UserStatus.Where(x => x.ShortName == StatusExternalUser).FirstOrDefault(); var systemUser = db.Users.Where(x => x.UserName == "system").FirstOrDefault(); user.StatusId = CurrentStatus.Id; user.CreationTime = DateTime.Now; user.CreatorUserId = systemUser.Id; user.IsActive = true; var UserResult = db.Users.Add(user); db.SaveChanges(); //Create rol #region Create rol bool UserRol = UserRoleService.CreateUserRol(UserResult.Id, user.Code); #endregion response.Message = "Usuario creado con exito"; return(Ok(response)); }