Ejemplo n.º 1
0
        public async Task CreateAsync_WorksCorectly()
        {
            MapperInitializer.InitializeMapper();
            var context           = ApplicationDbContextInMemoryFactory.InitializeContext();
            var addressRepository = new EfDeletableEntityRepository <Address>(context);
            var addressService    = new AddressService(addressRepository);

            var addressCreateInputModel = new AddressCreateInputModel()
            {
                City           = "TestCity",
                Street         = "TestStreet",
                BuildingNumber = "123",
                PostCode       = "223",
            };

            var emptyAddressCreateInputModel = new AddressCreateInputModel();

            var address = await addressService.CreateAsync(addressCreateInputModel);

            var actual = await context.Addresses.SingleOrDefaultAsync(x => x.City == "TestCity");

            Assert.NotNull(actual);
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await addressService.CreateAsync(emptyAddressCreateInputModel);
            });
        }
Ejemplo n.º 2
0
        public IActionResult Create(string userId)
        {
            var addressCreateInputModel = new AddressCreateInputModel();

            addressCreateInputModel.UserId = userId;

            return(this.View(addressCreateInputModel));
        }
Ejemplo n.º 3
0
        public async Task <int> UpdateAsync(AddressCreateInputModel input)
        {
            var address = await this.addressRepository.All().FirstOrDefaultAsync(x => x.Id == input.Id);

            address.City    = input.City;
            address.Country = input.Country;
            address.Street  = input.Street;
            address.ZipCode = input.ZipCode;

            this.addressRepository.Update(address);

            return(await this.addressRepository.SaveChangesAsync());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> CreateAsync(AddressCreateInputModel addressCreateInputModel)
        {
            if (await this.userService.UserHasThreeAddresses(addressCreateInputModel.UserId))
            {
                this.TempData["Error"] = UserCantHaveMoreThanThreeAddressesErrorMessage;
                return(this.RedirectToAction("Create", addressCreateInputModel));
            }

            var address = await this.addressService.CreateAsync(addressCreateInputModel);

            await this.usersAddressesService.CreateAsync(addressCreateInputModel.UserId, address.Id);

            return(this.Redirect($"/Users/Profile?userId={addressCreateInputModel.UserId}"));
        }
Ejemplo n.º 5
0
        public IActionResult Add(AddressCreateInputModel addressCreateInputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            string userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            AddressServiceModel addressServiceModel = addressCreateInputModel.To <AddressServiceModel>();

            this.addressesService.AddAddress(addressServiceModel, userId);

            return(this.Redirect("/Orders/Create"));
        }
Ejemplo n.º 6
0
        public async Task <Address> CreateAsync(AddressCreateInputModel addressCreateInputModel)
        {
            if (addressCreateInputModel.City == null ||
                addressCreateInputModel.Street == null ||
                addressCreateInputModel.PostCode == null)
            {
                throw new ArgumentNullException("Some of the adress properties were null.");
            }

            var address = addressCreateInputModel.To <Address>();

            await this.addressRepository.AddAsync(address);

            await this.addressRepository.SaveChangesAsync();

            return(address);
        }
        public async Task <IActionResult> Create(AddressCreateInputModel addressCreateInputModel)
        {
            await this.addressService.CreateAsync(addressCreateInputModel.To <AddressServiceModel>(), this.User.Identity.Name);

            return(this.RedirectToAction("Create", "Orders"));
        }