Example #1
0
        public async Task <ActionResult> Edit(string id)
        {
            var address = await this._addressesService
                          .GetAddressByIdAsync(id);

            if (address == null)
            {
                _logger.LogWarning($"Get(address) with {id} from DB - NOT FOUND");
                return(this.NotFound());
            }

            var model = new UpdateAddressModel
            {
                Id           = address.Id,
                Country      = address.Country,
                Region       = address.Region,
                Town         = address.Town,
                StreetName   = address.StreetName,
                AddressType  = address.AddressType,
                PropertyType = address.PropertyType,
                Number       = address.Number
            };

            if (address.PropertyType == PropertyType.Flat)
            {
                model.FlatModel = new AddFlatModel();

                model.FlatModel.Entrance  = address.Flat.Entrance;
                model.FlatModel.Floor     = address.Flat.Floor;
                model.FlatModel.Apartment = address.Flat.Apartment;
            }
            return(this.View("Preview", model));
        }
Example #2
0
        public async Task <IActionResult> Update(UpdateAddressModel model)
        {
            var idForUpdate     = model.Id;
            var addressToUpdate = await this._addressesService
                                  .GetAddressByIdAsync(idForUpdate);

            if (addressToUpdate == null)
            {
                _logger.LogWarning($"Get(address) with {model.Id} from DB - NOT FOUND");
                return(this.NotFound());
            }

            if (model.PropertyType == PropertyType.House)
            {
                ModelState["FlatModel.Apartment"].ValidationState = ModelValidationState.Valid;
            }

            if (!ModelState.IsValid)
            {
                return(this.View("Preview", model));
            }

            addressToUpdate.Country    = model.Country;
            addressToUpdate.Region     = model.Region;
            addressToUpdate.Town       = model.Town;
            addressToUpdate.Number     = model.Number;
            addressToUpdate.StreetName = model.StreetName;

            if (model.PropertyType == PropertyType.Flat)
            {
                if (addressToUpdate.Flat == null)
                {
                    addressToUpdate.Flat         = new Flat();
                    addressToUpdate.PropertyType = PropertyType.Flat;
                }

                addressToUpdate.Flat.Floor     = model.FlatModel.Floor;
                addressToUpdate.Flat.Entrance  = model.FlatModel.Entrance;
                addressToUpdate.Flat.Apartment = model.FlatModel.Apartment;
            }
            else
            {
                addressToUpdate.PropertyType = PropertyType.House;
                addressToUpdate.Flat         = null;
                //TODO flat delete from Db
            }
            await this._addressesService.UpdateAddressAsync(addressToUpdate);

            _logger.LogInformation($"Address with {addressToUpdate.Id} for user with {addressToUpdate.Id} has been updated");

            TempData["SuccessEditAddress"] = "The address has been successfully edited and saved!";

            return(this.RedirectToAction("Index", "Addresses"));
        }
        public async Task <ActionResult> Update(Guid uuid, UpdateAddressModel model)
        {
            var address = model.GetAddress(uuid);
            var result  = await _addressService.SaveAsync(address);

            if (!result.IsSuccessful)
            {
                return(FailResult(result));
            }
            if (await _unitOfWork.SaveChangesAsync())
            {
                return(NoContent());
            }
            return(ErrorResult());
        }
        public async Task UpdateShouldUpdateAnExistingRecord()
        {
            using var scope = ServiceProvider.CreateScope();
            var sut     = Factory.CreateClient();
            var context = scope.ServiceProvider.GetRequiredService <ApplicationContext>();

            var address = await SeedDatabaseFixture.AddDummyAddressAsync(context);

            const string newCity    = "ParaĆ­so do Tocantins";
            const string newZipCode = "335045-879";
            const string newCountry = "Bengium";
            const string newState   = "Test";
            const string newStreet  = "Another street";
            const int    newNumber  = 800;

            var editedAddress = new UpdateAddressModel()
            {
                City    = newCity,
                Country = newCountry,
                Number  = newNumber,
                State   = newState,
                Street  = newStreet,
                ZipCode = newZipCode,
                Id      = address.Id
            };

            var serializedJson = JsonSerializer.Serialize(editedAddress);
            var contentJson    = new StringContent(serializedJson, Encoding.UTF8, "application/json");

            var result = await sut.PutAsync($"Address/Update/{address.Uuid}", contentJson);

            result.EnsureSuccessStatusCode();

            var uniqueAddress = await context.Addresses.FirstAsync();

            Assert.NotEmpty(context.Addresses);
            Assert.Equal(newCity, uniqueAddress.City);
            Assert.Equal(newCountry, uniqueAddress.Country);
            Assert.Equal(newState, uniqueAddress.State);
            Assert.Equal(newZipCode, uniqueAddress.ZipCode);
            Assert.Equal(newStreet, uniqueAddress.Street);
            Assert.Equal(newNumber, uniqueAddress.Number);
            Assert.Equal(address.Uuid, uniqueAddress.Uuid);
        }
Example #5
0
        public ActionResult UpdateAddress(PreferenceAddressModel data)
        {
            SelectCustomerModel customerData = new SelectCustomerModel()
            {
                Email = data.email
            };
            CustomerResultModel customerResult = customerTable.SelectRecord(customerData);

            if (customerResult.CustomerUUID == null)
            {
                return(Json(new { result = "Fail", reason = "Invalid Customer" }));
            }

            UpdateAddressModel customerAddress = new UpdateAddressModel()
            {
                CustomerUUID = customerResult.CustomerUUID,

                BillingAddress  = data.streetName,
                BillingAddress2 = data.streetName2,
                BillingCity     = data.city,
                BillingState    = data.state,
                BillingZip      = data.postalCode,

                ShippingAddress  = data.streetName,
                ShippingAddress2 = data.streetName2,
                ShippingCity     = data.city,
                ShippingState    = data.state,
                ShippingZip      = data.postalCode
            };
            NonQueryResultModel updateResult = addressTable.UpdateRecord(customerAddress);

            if (updateResult.Success)
            {
                return(Json(new { result = "Success" }));
            }
            else
            {
                return(Json(new { result = "Fail", reason = "Database Update Failed" }));
            }
        }
Example #6
0
        public async Task <IActionResult> Save(UpdateAddressModel model)
        {
            var userId = this._userManager.GetUserId(this.User);
            var user   = await this._usersService.GetUserByIdAsync(userId);

            if (user == null)
            {
                _logger.LogWarning($"CurrentUser from DB - NOT FOUND");
                return(this.NotFound());
            }

            if (this._addressesService.CountOfAddressesPerUser(user) == 0)
            {
                model.AddressType = AddressType.Primary;
            }

            else
            {
                model.AddressType = AddressType.Alternative;
            }

            if (model.PropertyType == PropertyType.House)
            {
                ModelState["FlatModel.Apartment"].ValidationState = ModelValidationState.Valid;
            }

            //The model state is checked after the system allocate the type of the address automatically

            if (!ModelState.IsValid)
            {
                _logger.LogWarning($"Model State invalid for {nameof(UpdateAddressModel)}");
                return(this.View("Create"));
            }

            var addressToRegister = new Address
            {
                Country      = model.Country,
                Region       = model.Region,
                Town         = model.Town,
                StreetName   = model.StreetName,
                AddressType  = model.AddressType,
                PropertyType = model.PropertyType,
                Number       = model.Number,
                UserId       = userId
            };

            if (addressToRegister.PropertyType == PropertyType.Flat)
            {
                var flatToRegister = new Flat
                {
                    AddressId = addressToRegister.Id,
                    Entrance  = model.FlatModel.Entrance,
                    Floor     = model.FlatModel.Floor,
                    Apartment = model.FlatModel.Apartment
                };
                addressToRegister.Flat = flatToRegister;
            }


            await this._addressesService.CreateAddressAsync(addressToRegister);

            _logger.LogInformation($"Address with id {addressToRegister.Id} has been registered for user with id{user.Id}");
            TempData["SuccessCreatedAddress"] = "The address has been successfully saved!";

            return(this.RedirectToAction("Index", "Addresses"));
        }
Example #7
0
 public IActionResult CreatePost(UpdateAddressModel model)
 {
     return(this.View("Preview", model));
 }
Example #8
0
        public IActionResult Create()
        {
            var model = new UpdateAddressModel();

            return(this.View(model));
        }
 public ServiceResult UpdateAddress(UpdateAddressModel model)
 {
     new MerchantComponent().UpdateAddress(WorkContext.MerchantId, model.Postcode, model.Address, model.State, model.City);
     return(Result_OK(""));
 }