public IActionResult AddAnEmployeeAddress([FromBody] AddAddressDto addressDto) { if (addressDto == null) { return(BadRequest(ModelState)); } if (_npRepo.AddressExists(addressDto.Id)) { ModelState.AddModelError("", "Address already exists."); return(StatusCode(404, ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // var ContactInfoObj = _mapper.Map<CreateEmployeeDto, ContactInfo>(createEmployeeDto); var employeeAddressObj = _mapper.Map <AddAddressDto, Address>(addressDto); // employeePIObj.ContactInfo = ContactInfoObj; if (!_npRepo.CreateEmployeeAddress(employeeAddressObj)) { ModelState.AddModelError("", $"Something went wrong when saving the record {employeeAddressObj.Lot}"); return(StatusCode(500, ModelState)); } return(Ok()); }
public bool AddNewUser(AddNewUserDto newUser) { using (var db = new SqlConnection(_connectionString)) { var userNameExists = UserNameCheck(newUser.UserName); if (userNameExists) { return(false); } var newAddress = new AddAddressDto(); newAddress.AddressLine1 = newUser.AddressLine1; newAddress.AddressLine2 = newUser.AddressLine2; newAddress.City = newUser.City; newAddress.State = newUser.State; newAddress.ZipCode = newUser.ZipCode; newAddress.IsPreferred = true; var sql = @" INSERT INTO [User] ([IsSeller], [UserName], [FirstName], [LastName], [DateCreated], [FirebaseUid], [BusinessName]) OUTPUT INSERTED.Id VALUES (@isSeller, @userName, @firstName, @lastName, @dateCreated, @firebaseUid, @businessName)"; var userId = db.QueryFirst <Guid>(sql, newUser); if (userId != null) // This would be if there was no trouble creating the user { newAddress.UserId = userId; return(_addressRepo.AddNewAddress(newAddress)); } else // This would be if there WAS trouble creating the user { return(false); } } }
public bool AddNewAddress(AddAddressDto newAddress) { using (var db = new SqlConnection(_connectionString)) { var sql = @" INSERT INTO [UserAddress] ([UserId], [AddressLine1], [AddressLine2], [City], [State], [ZipCode], [IsPreferred]) VALUES (@userId, @addressLine1, @addressLine2, @city, @state, @zipCode, @isPreferred)"; return(db.Execute(sql, newAddress) == 1); } }