Exemplo n.º 1
0
        public void EditPostCargo(PostCargoEditDto postCargoEditDto)
        {
            var post = _postCargoRepository.GetById(postCargoEditDto.PostId);

            Location locationFrom = post.LocationFrom;

            locationFrom.Country  = _countryRepository.GetByName(postCargoEditDto.CountryFrom);
            locationFrom.Locality = _localityRepository.GetByName(postCargoEditDto.LocalityFrom);

            Location locationTo = post.LocationTo;

            locationTo.Country  = _countryRepository.GetByName(postCargoEditDto.CountryTo);
            locationTo.Locality = _localityRepository.GetByName(postCargoEditDto.LocalityTo);

            CargoSpecification cargoSpecification = post.Specification;

            cargoSpecification.Description = postCargoEditDto.CargoDescription;
            cargoSpecification.Weight      = postCargoEditDto.CargoWeight;
            cargoSpecification.Volume      = postCargoEditDto.CargoVolume;

            post.LocationTo    = locationTo;
            post.LocationFrom  = locationFrom;
            post.Specification = cargoSpecification;
            post.Price         = postCargoEditDto.Price;
            PostTransportType postTransportType;

            Enum.TryParse(postCargoEditDto.PostTransportTypes, true, out postTransportType);
            post.PostTransportType     = postTransportType;
            post.DateFrom              = postCargoEditDto.DateFrom;
            post.DateTo                = postCargoEditDto.DateTo;
            post.AdditionalInformation = postCargoEditDto.AdditionalInfo;

            _postCargoRepository.Update(post);
        }
Exemplo n.º 2
0
        public void CreatePostCargo(PostCargoCreateDto createPostCargoDto, ApplicationUser user)
        {
            Location locationFrom = new Location()
            {
                Country  = _countryRepository.GetByName(createPostCargoDto.CountryFrom),
                Locality = _localityRepository.GetByName(createPostCargoDto.LocalityFrom)
            };

            Location locationTo = new Location()
            {
                Country  = _countryRepository.GetByName(createPostCargoDto.CountryTo),
                Locality = _localityRepository.GetByName(createPostCargoDto.LocalityTo)
            };

            CargoSpecification cargoSpecification = new CargoSpecification()
            {
                Description = createPostCargoDto.CargoDescription,
                Weight      = createPostCargoDto.CargoWeight,
                Volume      = createPostCargoDto.CargoVolume
            };

            var postFactory = new PostFactory();
            var post        = postFactory.CreateNewPost(user, createPostCargoDto.DateFrom, createPostCargoDto.DateTo, locationFrom, locationTo,
                                                        createPostCargoDto.PostTransportTypes, createPostCargoDto.Price, createPostCargoDto.AdditionalInfo, cargoSpecification);

            _locationRepository.Save(locationFrom);
            _locationRepository.Save(locationTo);
            _cargospecRepository.Save(cargoSpecification);
            _postCargoRepository.Save(post as PostCargo);
        }