コード例 #1
0
        public async Task CreateShouldWorkCorrectly(
            string country,
            string state,
            string city,
            string description,
            string postalCode,
            string phoneNumber)
        {
            const string userId = TestUser.Identifier;

            var request = new AddressesRequestModel
            {
                Country     = country,
                State       = state,
                City        = city,
                Description = description,
                PostalCode  = postalCode,
                PhoneNumber = phoneNumber
            };

            var id = await this.addresses.CreateAsync(request, userId);

            var address = await this.Data.Addresses.FindAsync(id);

            address.Id.ShouldBe(id);
            address.Country.ShouldBe(request.Country);
            address.State.ShouldBe(request.State);
            address.Description.ShouldBe(request.Description);
            address.PostalCode.ShouldBe(request.PostalCode);
            address.PhoneNumber.ShouldBe(request.PhoneNumber);
            address.UserId.ShouldBe(userId);
        }
コード例 #2
0
        public async Task <ActionResult> Create(
            AddressesRequestModel model)
        {
            var userId = this.currentUser.UserId;

            var id = await this.addresses.CreateAsync(model, userId);

            return(Created(nameof(this.Create), id));
        }
コード例 #3
0
        public async Task <int> CreateAsync(
            AddressesRequestModel model, string userId)
        {
            var address = new Address
            {
                Country     = model.Country,
                State       = model.State,
                City        = model.City,
                Description = model.Description,
                PostalCode  = model.PostalCode,
                PhoneNumber = model.PhoneNumber,
                UserId      = userId
            };

            await this.Data.AddAsync(address);

            await this.Data.SaveChangesAsync();

            return(address.Id);
        }