Esempio n. 1
0
        public async Task <string> CreateAsync(AddressInputModel inputModel)
        {
            var address = inputModel.Map <AddressInputModel, Address>();

            var townId = await _townsService.GetIdByNameAsync(inputModel.TownName);

            address.TownId = townId;

            var createdAddress = _context.Addresses.Add(address).Entity;
            await _context.SaveChangesAsync();

            return(createdAddress.Id);
        }
Esempio n. 2
0
        public async Task UpdateAsync(string id, AddressInputModel inputModel)
        {
            this.ThrowIfIncorrectId(_context.Addresses, id);

            var address = await _context.Addresses
                          .FirstOrDefaultAsync(x => x.Id == id);

            _context.Entry(address).State = EntityState.Detached;

            address    = inputModel.Map <AddressInputModel, Address>();
            address.Id = id;

            _context.Addresses.Update(address);
            await _context.SaveChangesAsync();
        }