예제 #1
0
        public IHttpActionResult PutOrganizationTaxAddress(int id, OrganizationTaxAddressDTO organizationTaxAddress)
        {
            if (organizationTaxAddress == null || !ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != organizationTaxAddress.Id)
            {
                return(BadRequest());
            }
            try
            {
                OrganizationTaxAddress address    = organizationTaxAddress.FromDTO();
                UnitOfWork             unitOfWork = new UnitOfWork(factory);
                unitOfWork.OrganizationTaxAddressesRepository.Update(address);
                unitOfWork.Save();
                OrganizationTaxAddressDTO dto = unitOfWork.OrganizationTaxAddressesRepository
                                                .Get(d => d.Id == id, includeProperties: "Address,Address.Country,Address.AddressLocality,Address.AddressPlace,Address.AddressRegion,Address.AddressVillage")
                                                .FirstOrDefault().ToDTO();

                return(Ok(dto));
            }
            catch (NotFoundException nfe)
            {
                return(NotFound());
            }
            catch (ConflictException ce)
            {
                return(Conflict());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
예제 #2
0
        public IHttpActionResult PostOrganizationTaxAddress(OrganizationTaxAddressDTO organizationTaxAddress)
        {
            if (organizationTaxAddress == null)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                OrganizationTaxAddress address    = organizationTaxAddress.FromDTO();
                UnitOfWork             unitOfWork = new UnitOfWork(factory);
                address.Id         = address.NewId(unitOfWork);
                address.Address.Id = address.Address.NewId(unitOfWork);
                address.AddressId  = address.Address.Id;
                unitOfWork.OrganizationTaxAddressesRepository.Insert(address);
                unitOfWork.Save();

                OrganizationTaxAddressDTO dto = unitOfWork.OrganizationTaxAddressesRepository
                                                .Get(d => d.Id == address.Id, includeProperties: "Address,Address.Country,Address.AddressLocality,Address.AddressPlace,Address.AddressRegion,Address.AddressVillage")
                                                .FirstOrDefault().ToDTO();

                return(CreatedAtRoute("GetOrganizationTaxAddress", new { id = dto.Id }, dto));
            }
            catch (NotFoundException nfe)
            {
                return(NotFound());
            }
            catch (ConflictException ce)
            {
                return(Conflict());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }