public int AddNewAddress(NewAddressVm newAddressVm)
        {
            newAddressVm.Voivodeship = GetVoivedoshipNameById(newAddressVm.Voivodeship);
            var isId = int.TryParse(newAddressVm.City, out int cityId);

            if (isId == true)
            {
                newAddressVm.City = GetCityNameById(cityId);
            }
            else
            {
                newAddressVm.City = "City name is inccorrect";
            }
            newAddressVm.CityType  = GetCityTypeById(newAddressVm.CityType);
            newAddressVm.Community = GetCommunityNameById(newAddressVm.Community);
            newAddressVm.District  = GetDistrictNameById(newAddressVm.District);

            var newAddress = _mapper.Map <Address>(newAddressVm);

            newAddress.CreatedDateTime = DateTime.Now;
            newAddress.IsActive        = true;
            newAddress.CreatedById     = newAddress.ApplicationUserID;
            var isSuccesAddNewAddress = _addressRepository.AddNewAddress(newAddress);

            return(isSuccesAddNewAddress);
        }
        public HttpResponseMessage AddNewAddress(AddressModel model)
        {
            ResponseStatus response = new ResponseStatus();

            //AddressModel data = new AddressModel();

            try
            {
                if (ModelState.IsValid)
                {
                    var result = _repository.AddNewAddress(model);
                    if (result.AddressId > 0)
                    {
                        response.serverResponseTime = System.DateTime.Now;
                        response.isSuccess          = true;
                        return(Request.CreateResponse(HttpStatusCode.OK, new { result, response }));
                    }
                    else
                    {
                        response.serverResponseTime = System.DateTime.Now;
                        response.isSuccess          = false;
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, new { response }));
                    }
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Something Worng !"));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Something Worng !", ex));
            }
        }
Esempio n. 3
0
 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);
         }
     }
 }
Esempio n. 4
0
 public void AddNewAddress(AddressDto address)
 {
     _addressRepository.AddNewAddress(_mapper.Map <AddressDto, Address>(address));
 }
Esempio n. 5
0
 public bool AddNewAddress(AddressDto address)
 {
     return(_addressRepository.AddNewAddress(_mapper.Map <AddressDto, Address>(address)));
 }