Пример #1
0
        /// <summary>
        /// news a account
        /// </summary>
        /// <param name="accountDTO"></param>
        /// <returns></returns>
        public GooderProudctDTO AddNewProudct(GooderProudctDTO proudctDTO)
        {
            //check preconditions
            if (proudctDTO == null)
            {
                throw new ArgumentException(Messages.warning_CannotAddGooderProudctWithEmptyInformation);
            }

            var account = _accountRepository.Get(proudctDTO.AccountId);

            if (account != null)
            {
                var product = GooderProudctFactory.CreateGooderProudct(proudctDTO.AccountId,
                                                                       proudctDTO.Name, proudctDTO.SourceCity, proudctDTO.DestCityFrist, proudctDTO.DestCitySecond,
                                                                       proudctDTO.DestCityThird, proudctDTO.CarLength, proudctDTO.CarType, proudctDTO.GooderVolume,
                                                                       proudctDTO.GooderHeight, proudctDTO.LayStartTime, proudctDTO.LayEndTime, proudctDTO.UnitPrice,
                                                                       proudctDTO.Transferway, proudctDTO.Payway, proudctDTO.Remark, proudctDTO.IsRefresh,
                                                                       proudctDTO.Lat, proudctDTO.Lng);

                //save entity
                SaveProdect(product, account);

                //return the data with id and assigned default values
                return(product.ProjectedAs <GooderProudctDTO>());
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// update a user info
        /// </summary>
        /// <param name="customerDTO"></param>
        public void UpdateProudct(GooderProudctDTO proudctDTO)
        {
            if (proudctDTO == null || proudctDTO.Id == Guid.Empty)
            {
                throw new ArgumentException(Messages.warning_CannotUpdateProudctWithEmptyInformation);
            }

            //get persisted item
            var persisted = _proudctRepository.Get(proudctDTO.Id);

            if (persisted != null) //if customer exist
            {
                //materialize from customer dto
                var current = MaterializeAccountFromDto(proudctDTO);

                //Merge changes
                _proudctRepository.Merge(persisted, current);

                //commit unit of work
                _proudctRepository.UnitOfWork.Commit();
            }
            else
            {
                LoggerFactory.CreateLog().LogWarning(Messages.warning_CannotUpdateNonExistingProudct);
            }
        }
Пример #3
0
        GooderProudct MaterializeAccountFromDto(GooderProudctDTO proudctDTO)
        {
            var current = GooderProudctFactory.CreateGooderProudct(proudctDTO.AccountId,
                                                                   proudctDTO.Name, proudctDTO.SourceCity, proudctDTO.DestCityFrist, proudctDTO.DestCitySecond,
                                                                   proudctDTO.DestCityThird, proudctDTO.CarLength, proudctDTO.CarType, proudctDTO.GooderVolume,
                                                                   proudctDTO.GooderHeight, proudctDTO.LayStartTime, proudctDTO.LayEndTime, proudctDTO.UnitPrice,
                                                                   proudctDTO.Transferway, proudctDTO.Payway, proudctDTO.Remark, proudctDTO.IsRefresh,
                                                                   proudctDTO.Lat, proudctDTO.Lng);


            current.ChangeCurrentIdentity(proudctDTO.Id);


            return(current);
        }