public async Task <IHttpActionResult> Post([FromBody] Address entity)
        {
            logger.Trace("Call AddressController Post");

            var record = await AddressRepository.CreateAsync(entity);

            return(Created(record));
        }
Example #2
0
        public async Task <AddressViewModel> Post(Guid contactId, [FromBody] AddressViewModel model)
        {
            _logger.LogInformation($"add.address contact: {contactId}");
            AssertValidIds(contactId);
            var data  = _mapper.Map <Address>(model);
            var saved = await _repository.CreateAsync(contactId, data);

            _logger.LogInformation($"added.address contact: {contactId} record: {saved.Id}");
            return(_mapper.Map <AddressViewModel>(saved));
        }
Example #3
0
        public async Task <AddressDto> CreateAddressAsync(int id, CreateAddress createAddress)
        {
            var user = await _userRepository.GetAsync(id);

            user.ThrowIfNull(id);
            var address = await _addressRepository.CreateAsync(_mapper.Map <Address>(createAddress));

            user.AddressId = address.Id;
            await _userRepository.UpdateAsync(user);

            return(_mapper.Map <AddressDto>(address));
        }
        public async Task <IActionResult> Create([FromBody] Address address)
        {
            if (address == null)
            {
                return(BadRequest());
            }

            if (address.FullAddress == null)
            {
                return(BadRequest());
            }

            Address added = await addressRepository.CreateAsync(address);

            return(CreatedAtRoute("GetAddress", new { id = added.Id }, address));
        }
 public async Task <IActionResult> Upsert(Address obj)
 {
     if (ModelState.IsValid)
     {
         if (obj.Id == 0)
         {
             await _addressRepository.CreateAsync(APISetting.AddressAPIPath, obj, HttpContext.Session.GetString("JWToken"));
         }
         else
         {
             await _addressRepository.UpdateAsync(APISetting.AddressAPIPath + obj.Id, obj, HttpContext.Session.GetString("JWToken"));
         }
         return(RedirectToAction(nameof(Index)));
     }
     else
     {
         return(View(obj));
     }
 }
Example #6
0
        public async Task <IActionResult> Create([FromBody] Address c)
        {
            if (c == null)
            {
                return(BadRequest()); // 400 Bad request
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState)); // 400 Bad request
            }

            Address added = await repo.CreateAsync(c);

            return(CreatedAtRoute( // 201 Created
                       routeName: nameof(GetAddress),
                       routeValues: new { id = added.AddressId.ToString().ToLower() },
                       value: added));
        }
Example #7
0
        public async Task <int> CreateAsync(Customer customer)
        {
            ValidateCustomerInputs(customer);
            var addressId = await _addressRepository.CreateAsync(new Address
            {
                Address1      = customer.Address1,
                Address2      = customer.Address2,
                Phone         = customer.Phone,
                PostalCode    = customer.PostalCode,
                CreatedBy     = customer.CreatedBy,
                LastUpdatedBy = customer.LastUpdatedBy,
                CreatedDate   = DateTime.UtcNow,
                LastUpdated   = DateTime.UtcNow,
                City          = new City
                {
                    Name          = customer.City,
                    CreatedBy     = customer.CreatedBy,
                    LastUpdatedBy = customer.LastUpdatedBy,
                    CreatedDate   = DateTime.UtcNow,
                    LastUpdated   = DateTime.UtcNow,
                    Country       = new Country
                    {
                        Name          = customer.Country,
                        CreatedBy     = customer.CreatedBy,
                        LastUpdatedBy = customer.LastUpdatedBy,
                        CreatedDate   = DateTime.UtcNow,
                        LastUpdated   = DateTime.UtcNow,
                    }
                }
            });

            customer.AddressId   = addressId;
            customer.CreatedDate = DateTime.UtcNow;
            customer.LastUpdated = DateTime.UtcNow;
            var customerId = await _sqlOrm.CreateEntityAsync(CreateSql.Customer, customer);

            return(customerId);
        }
Example #8
0
        public async Task <IActionResult> CreateAddress(string personId, Address address)
        {
            await _addressRepository.CreateAsync(personId, address);

            return(Ok());
        }