Esempio n. 1
0
        /// <summary>
        /// update a user info
        /// </summary>
        /// <param name="specwayDTO"></param>
        public void UpdateSpecway(SpecwayDTO specwayDTO)
        {
            if (specwayDTO == null || specwayDTO.Id == Guid.Empty)
            {
                throw new ArgumentException(Messages.warning_CannotUpdateSpecwayWithEmptyInformation);
            }

            //get persisted item
            var persisted = _specwayRepository.Get(specwayDTO.Id);

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

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

                //commit unit of work
                _specwayRepository.UnitOfWork.Commit();
            }
            else
            {
                LoggerFactory.CreateLog().LogWarning(Messages.warning_CannotUpdateNonExistingSpecway);
            }
        }
Esempio n. 2
0
        Specway MaterializeSpecwayFromDto(SpecwayDTO specwayDTO)
        {
            var current = SpecwayFactory.CreateSpecway(specwayDTO.AccountId, specwayDTO.Name, specwayDTO.SourcePrivince, specwayDTO.SourceCity,
                                                       specwayDTO.SourceArea, specwayDTO.SourceAddress, specwayDTO.SourceTelehone, specwayDTO.SourceMobile, specwayDTO.DestCity, specwayDTO.DestCity1,
                                                       specwayDTO.DestCity2, specwayDTO.DestCity3, specwayDTO.HeadUrl, specwayDTO.CardPositiveUrl, specwayDTO.CardnegativeUrl, specwayDTO.BusinessUrl,
                                                       specwayDTO.Remark, specwayDTO.ViewCount, specwayDTO.SceneUrl1, specwayDTO.SceneUrl2, specwayDTO.SceneUrl3, specwayDTO.SceneUrl4, specwayDTO.SceneUrl5, specwayDTO.SceneUrl6, specwayDTO.SceneUrl7, specwayDTO.SceneUrl8, specwayDTO.SceneUrl9, specwayDTO.SceneUrl10, specwayDTO.SceneUrl11, specwayDTO.SceneUrl12, specwayDTO.SceneUrl13, specwayDTO.SceneUrl14, specwayDTO.SceneUrl15, specwayDTO.SceneUrl16, specwayDTO.SceneUrl17, specwayDTO.SceneUrl18, specwayDTO.Lng, specwayDTO.Lat
                                                       );

            current.ChangeCurrentIdentity(current.Id);

            return(current);
        }
        public IHttpActionResult Post([FromBody] SpecwayDTO specDTO)
        {
            if (specDTO == null || specDTO.AccountId == Guid.Empty)
            {
                throw new ArgumentException();
            }

            var accountDTO = this._accountAppService.FindAccount(specDTO.AccountId);

            if (accountDTO == null)
            {
                return(Ok(Messages.error_ValidateUserLoging));
            }

            if (!accountDTO.IsEnabled)
            {
                return(Ok(Messages.error_ValidateMobileFreeze));
            }

            if (accountDTO.UserType == (int)UserType.CarUser)
            {
                return(Ok(Messages.error_ValidateCarUser));
            }

            //get lng and lat
            float lat = 0, lng = 0;

            if (new AddressController().Get(specDTO.SourceAddress, out lng, out lat))
            {
                specDTO.Lng = lng;
                specDTO.Lat = lat;
            }

            var resultSpectWayDTO = this._specwayAppService.AddNewSpecway(specDTO);

            if (resultSpectWayDTO == null)
            {
                throw new NotImplementedException();
            }

            return(Ok());
        }
Esempio n. 4
0
        /// <summary>
        /// news a account
        /// </summary>
        /// <param name="praiseDTO"></param>
        /// <returns></returns>
        public SpecwayDTO AddNewSpecway(SpecwayDTO specwayDTO)
        {
            //check preconditions
            if (specwayDTO == null)
            {
                throw new ArgumentException(Messages.warning_CannotAddSpecwayWithEmptyInformation);
            }

            //Create the entity and the required associated data
            var specway = SpecwayFactory.CreateSpecway(specwayDTO.AccountId, specwayDTO.Name, specwayDTO.SourcePrivince, specwayDTO.SourceCity,
                                                       specwayDTO.SourceArea, specwayDTO.SourceAddress, specwayDTO.SourceTelehone, specwayDTO.SourceMobile, specwayDTO.DestCity, specwayDTO.DestCity1,
                                                       specwayDTO.DestCity2, specwayDTO.DestCity3, specwayDTO.HeadUrl, specwayDTO.CardPositiveUrl, specwayDTO.CardnegativeUrl, specwayDTO.BusinessUrl,
                                                       specwayDTO.Remark, specwayDTO.ViewCount, specwayDTO.SceneUrl1, specwayDTO.SceneUrl2, specwayDTO.SceneUrl3, specwayDTO.SceneUrl4, specwayDTO.SceneUrl5, specwayDTO.SceneUrl6, specwayDTO.SceneUrl7, specwayDTO.SceneUrl8, specwayDTO.SceneUrl9, specwayDTO.SceneUrl10, specwayDTO.SceneUrl11, specwayDTO.SceneUrl12, specwayDTO.SceneUrl13, specwayDTO.SceneUrl14, specwayDTO.SceneUrl15, specwayDTO.SceneUrl16, specwayDTO.SceneUrl17, specwayDTO.SceneUrl18, specwayDTO.Lng, specwayDTO.Lat
                                                       );

            //save entity
            SaveSpecway(specway);

            //return the data with id and assigned default values
            return(specway.ProjectedAs <SpecwayDTO>());
        }
        // PUT: api/specway/5
        public IHttpActionResult Put(string action, Guid adminId, [FromBody] SpecwayDTO specDTO)
        {
            if (specDTO.Id == Guid.Empty || string.IsNullOrEmpty(action))
            {
                throw new ArgumentException();
            }

            if (action == "vipReflus")
            {
                var accountDTO = this._accountAppService.FindAccount(specDTO.AccountId);

                if (accountDTO == null)
                {
                    return(Ok(Messages.error_ValidateUserLoging));
                }

                if (!accountDTO.IsEnabled)
                {
                    return(Ok(Messages.error_ValidateMobileFreeze));
                }

                if (accountDTO.UserType == (int)UserType.CarUser)
                {
                    return(Ok(Messages.error_ValidateCarUser));
                }


                if (specDTO == null)
                {
                    return(NotFound());
                }

                var vipDTO = _vipAppService.FindVip(specDTO.AccountId);

                if (vipDTO == null || vipDTO.EndDateTime < DateTime.Now)
                {
                    return(Ok <string>(Messages.error_ValidateNotVIPReflus));
                }

                specDTO.LateDate = DateTime.Now;

                _specwayAppService.UpdateSpecway(specDTO);

                return(Ok());
            }
            else if (action == "adminAudite")
            {
                var adminDto = this._accountAppService.FindAccount(adminId);

                if (adminDto == null || adminDto.UserType != 2)
                {
                    return(Ok <string>(Messages.error_ValidateNotAdmin));
                }

                specDTO.IsEnabled = !specDTO.IsEnabled;

                this._specwayAppService.UpdateSpecway(specDTO);

                return(Ok());
            }
            else if (action == "userEdit")
            {
                if (specDTO == null)
                {
                    return(NotFound());
                }

                var accountDTO = this._accountAppService.FindAccount(specDTO.AccountId);

                if (accountDTO == null)
                {
                    return(Ok(Messages.error_ValidateUserLoging));
                }

                if (!accountDTO.IsEnabled)
                {
                    return(Ok(Messages.error_ValidateMobileFreeze));
                }

                if (accountDTO.UserType == (int)UserType.CarUser)
                {
                    return(Ok(Messages.error_ValidateCarUser));
                }

                specDTO.IsEnabled = false;

                this._specwayAppService.UpdateSpecway(specDTO);

                return(Ok());
            }

            throw new ArgumentNullException();
        }