public MainWindowViewModel()
        {
            #region starting view content
            logHandler = LogHandler.Instance;
            logHandler.MainWindowViewModel = this;
            ContentHandler.StartContent();
            Refresh();
            #endregion

            #region Commands
            AddUserCommand            = new AddUserCommand(this);
            ViewProfilInfoCommand     = new ViewProfilInfoCommand(this);
            AddTelephoneCommand       = new AddTelephoneCommand(this);
            AddShopCommand            = new AddShopCommand(this);
            ChangeTelephoneCommand    = new ChangeTelephoneInfoCommand(this);
            DeleteTelephoneCommand    = new DeleteTelephoneCommand(this);
            DuplicateTelephoneCommand = new DuplicateTelephoneCommand(this);
            ChangeShopCommand         = new ChangeShopInfoCommand(this);
            DeleteShopCommand         = new DeleteShopCommand(this);
            LogOutCommand             = new LogOutCommand(this);
            BuyTelephoneCommand       = new BuyTelephoneCommand(this);
            ClearCommand   = new ClearCommand(this);
            UndoCommand    = new UndoCommand(this);
            RedoCommand    = new RedoCommand(this);
            FilterCommand  = new FilterCommand(this);
            RefreshCommand = new RefreshCommand(this);
            #endregion
        }
 public AddShopViewModel(IDataStore dataStore, UpdateAppStatusDelegate del) :
     base(dataStore, del)
 {
     AddShopCommand = new AddShopCommand(this);
     _data.ShopActionEventHandler      += OnShopActionEventHandler;
     _data.ShopActionErrorEventHandler += OnShopActionErrorEventHandler;
 }
Exemplo n.º 3
0
        public async Task <IActionResult> Execute(JObject obj, HttpRequest request, string subject, string commonId)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (string.IsNullOrWhiteSpace(subject))
            {
                throw new ArgumentNullException(nameof(subject));
            }

            // 1. Check the request
            AddShopCommand command = null;

            try
            {
                command = _requestBuilder.GetAddShop(obj);
            }
            catch (ArgumentException ex)
            {
                var error = _responseBuilder.GetError(ErrorCodes.Request, ex.Message);
                return(_controllerHelper.BuildResponse(HttpStatusCode.BadRequest, error));
            }

            var validationResult = await _addShopValidator.Validate(command, subject);

            if (!validationResult.IsValid)
            {
                var error = _responseBuilder.GetError(ErrorCodes.Request, validationResult.Message);
                return(_controllerHelper.BuildResponse(HttpStatusCode.BadRequest, error));
            }

            command.Id             = Guid.NewGuid().ToString();
            command.CreateDateTime = DateTime.UtcNow;
            command.UpdateDateTime = DateTime.UtcNow;
            command.Subject        = subject;
            command.CommonId       = commonId;
            if (!string.IsNullOrWhiteSpace(command.BannerImage))
            {
                string bannerImage = null;
                if (AddImage(command.BannerImage, request, "banner", out bannerImage))
                {
                    command.BannerImage = bannerImage;
                }
            }

            if (!string.IsNullOrWhiteSpace(command.ProfileImage))
            {
                string profileImage = null;
                if (AddImage(command.ProfileImage, request, "profile", out profileImage))
                {
                    command.ProfileImage = profileImage;
                }
            }

            var res = new { id = command.Id };

            _commandSender.Send(command);
            return(new OkObjectResult(res));
        }
Exemplo n.º 4
0
        public async Task <AddShopValidationResult> Validate(AddShopCommand shop, string subject)
        {
            if (shop == null)
            {
                throw new ArgumentNullException(nameof(shop));
            }

            if (string.IsNullOrWhiteSpace(subject))
            {
                throw new ArgumentNullException(nameof(subject));
            }

            // 1. Check category.
            var category = await _categoryRepository.Get(shop.CategoryId);

            if (category == null)
            {
                return(new AddShopValidationResult(ErrorDescriptions.TheCategoryDoesntExist));
            }

            // 2. Check the user doesn't already have a shop on the same category.
            var searchResult = await _shopRepository.Search(new SearchShopsParameter
            {
                CategoryIds = new[] { shop.CategoryId },
                Subjects    = new[] { subject }
            });

            if (searchResult.Content != null && searchResult.Content.Any())
            {
                return(new AddShopValidationResult(ErrorDescriptions.TheShopCannotBeAddedBecauseThereIsAlreadyOneInTheCategory));
            }

            // 3. Check mandatory parameters.
            if (!IsValid(shop.Name, 1, 15))
            {
                return(new AddShopValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatoryAndShouldContainsBetween, Constants.DtoNames.Shop.Name, 1, 15)));
            }

            if (!IsValid(shop.Description, 1, 255))
            {
                return(new AddShopValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatoryAndShouldContainsBetween, Constants.DtoNames.Shop.Description, 5, 15)));
            }

            if (!IsValid(shop.GooglePlaceId))
            {
                return(new AddShopValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatory, Constants.DtoNames.Shop.GooglePlaceId)));
            }

            if (!IsValid(shop.StreetAddress))
            {
                return(new AddShopValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatory, Constants.DtoNames.Shop.StreetAddress)));
            }

            if (!IsValid(shop.PostalCode))
            {
                return(new AddShopValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatory, Constants.DtoNames.Shop.PostalCode)));
            }

            if (!IsValid(shop.Locality))
            {
                return(new AddShopValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatory, Constants.DtoNames.Shop.Locality)));
            }

            if (!IsValid(shop.Country))
            {
                return(new AddShopValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatory, Constants.DtoNames.Shop.Country)));
            }

            if (shop.ProductCategories != null)
            {
                if (shop.ProductCategories.Any(f => string.IsNullOrWhiteSpace(f.Name)))
                {
                    return(new AddShopValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatory, Constants.DtoNames.Shop.ProductCategories + "." + Constants.DtoNames.ProductCategory.Name)));
                }

                if (shop.ProductCategories.GroupBy(c => c.Name).Any(kvp => kvp.Count() > 1))
                {
                    return(new AddShopValidationResult(string.Format(ErrorDescriptions.DuplicateValues, Constants.DtoNames.Shop.ProductCategories)));
                }

                if (shop.ProductCategories.Count() > 8)
                {
                    return(new AddShopValidationResult(ErrorDescriptions.OnlyEightCategoriesCanBeAdded));
                }
            }

            if (shop.ProductFilters != null)
            {
                if (shop.ProductFilters.Any(f => string.IsNullOrWhiteSpace(f.Name)))
                {
                    return(new AddShopValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatory, Constants.DtoNames.Shop.Filters + "." + Constants.DtoNames.Filter.Name)));
                }

                if (shop.ProductFilters.Any(f => f.Values == null || !f.Values.Any()))
                {
                    return(new AddShopValidationResult(string.Format(ErrorDescriptions.TheParameterIsMandatory, Constants.DtoNames.Shop.Filters + "." + Constants.DtoNames.Filter.Values)));
                }

                if (shop.ProductFilters.GroupBy(c => c.Name).Any(kvp => kvp.Count() > 1))
                {
                    return(new AddShopValidationResult(string.Format(ErrorDescriptions.DuplicateValues, Constants.DtoNames.Shop.Filters)));
                }

                if (shop.ProductFilters.Any(p => p.Values.GroupBy(v => v).Count() != p.Values.Count()))
                {
                    return(new AddShopValidationResult(string.Format(ErrorDescriptions.DuplicateValues, Constants.DtoNames.Shop.Filters + "." + Constants.DtoNames.Filter.Values)));
                }
            }

            return(new AddShopValidationResult(category));
        }