Example #1
0
        public override void Execute()
        {
            if (Repository.Query(whereSpecification: new UserByLoginWhereSpec(Login))
                .Any())
            {
                throw IncWebException.For <AddUserCommand>(r => r.Login, "Login not unique");
            }

            var user = new User
            {
                Login     = Login,
                Password  = Password,
                Activated = false
            };

            Repository.Save(user);

            string urlConfirm = PathResult + "?UserId={0}".F(user.Id.ReturnOrDefault(r => r, "Debug"));

            EventBroker.Publish(new OnSendEmailEvent
            {
                To      = Login,
                Subject = "Confirm registration",
                Body    = "Please confirm email {0}".F(urlConfirm)
            });

            EventBroker.Publish(new OnChangeSearchItemEvent(user));
        }
        protected async Task <ActionResult> TryPushAsync(Func <CommandComposite, Task> push, CommandComposite composite, Action <IncTryPushSetting> action = null, bool?isAjax = null)
        {
            var setting = new IncTryPushSetting();

            action.Do(r => r(setting));

            Func <ActionResult> defaultSuccess = () => View(composite.Parts[0]);
            var isActualAjax = isAjax.GetValueOrDefault(HttpContext.Request.IsAjaxRequest());

            if (isActualAjax)
            {
                defaultSuccess = () => IncodingResult.Success();
            }
            var success = setting.SuccessResult ?? defaultSuccess;

            Func <IncWebException, ActionResult> defaultError = (ex) => View(composite.Parts[0]);

            if (isActualAjax)
            {
                defaultError = (ex) => IncodingResult.Error((ModelStateDictionary)ModelState);
            }
            var error = setting.ErrorResult ?? defaultError;

            if (!ModelState.IsValid)
            {
                return(error(IncWebException.For(string.Empty, string.Empty)));
            }

            try
            {
                await push(composite);

                return(success());
            }
            catch (IncWebException exception)
            {
                foreach (var pairError in exception.Errors)
                {
                    foreach (var errorMessage in pairError.Value)
                    {
                        ModelState.AddModelError(pairError.Key, errorMessage);
                    }
                }

                return(error(exception));
            }
        }
Example #3
0
        public override void Execute()
        {
            var user = Repository.Query(whereSpecification: new UserByLoginWhereSpec(Email)).SingleOrDefault();

            if (user == null)
            {
                throw IncWebException.For <ForgotUserPasswordCommand>(r => r.Email, "User not exists");
            }

            user.ResetToken = Token;
            EventBroker.Publish(new OnSendEmailEvent
            {
                To      = Email,
                Subject = "Your new random password from Browsio",
                Body    = "Please follow the link to change password : <a=href\"{0}\"".F(ChangePasswordUrl)
            });
        }
        protected ActionResult TryPush(CommandComposite composite, Action <IncTryPushSetting> action = null)
        {
            var setting = new IncTryPushSetting();

            action.Do(r => r(setting));

            Func <ActionResult> defaultSuccess = () => View(composite.Parts[0]);

            if (HttpContext.Request.IsAjaxRequest())
            {
                defaultSuccess = () => IncodingResult.Success();
            }
            var success = setting.SuccessResult ?? defaultSuccess;

            Func <IncWebException, ActionResult> defaultError = (ex) => View(composite.Parts[0]);

            if (HttpContext.Request.IsAjaxRequest())
            {
                defaultError = (ex) => IncodingResult.Error(ModelState);
            }
            var error = setting.ErrorResult ?? defaultError;

            if (!ModelState.IsValid)
            {
                return(error(IncWebException.For(string.Empty, string.Empty)));
            }

            try
            {
                dispatcher.Push(composite);
                return(success());
            }
            catch (IncWebException exception)
            {
                foreach (var pairError in exception.Errors)
                {
                    foreach (var errorMessage in pairError.Value)
                    {
                        ModelState.AddModelError(pairError.Key, errorMessage);
                    }
                }

                return(error(exception));
            }
        }
Example #5
0
        public override void Execute()
        {
            var categoryOfType = (CategoryOfType)Category;

            var store = Repository.GetById <Store>(Id);

            if (store.Category != categoryOfType && Repository.Query(whereSpecification: new StoreByCategoryOptWhereSpec(categoryOfType).And(new StoreByUserWhereSpec(BrowsioApp.UserId)))
                .Any())
            {
                throw IncWebException.For <AddStoreCommand>(r => r.Category, "Store with {0} category exist".F(categoryOfType.ToLocalization()));
            }

            store.Category    = categoryOfType;
            store.Name        = Name;
            store.Description = Description;
            store.Genre       = Repository.GetById <Genre>(GenreId);
            if (Image != null)
            {
                store.Image = new HttpMemoryPostedFile(Image).ContentAsBytes;
            }

            EventBroker.Publish(new OnChangeSearchItemEvent(store));
        }
Example #6
0
        public override void Execute()
        {
            var categoryOfType = (CategoryOfType)Category;

            if (Repository.Query(whereSpecification: new StoreByCategoryOptWhereSpec(categoryOfType).And(new StoreByUserWhereSpec(BrowsioApp.UserId)))
                .Any())
            {
                throw IncWebException.For <AddStoreCommand>(r => r.Category, "Store with {0} category exist".F(categoryOfType.ToLocalization()));
            }

            var user  = Repository.GetById <User>(BrowsioApp.UserId);
            var store = new Store
            {
                Category    = categoryOfType,
                Description = Description,
                Image       = Image.ReturnOrDefault(@base => new HttpMemoryPostedFile(@base).ContentAsBytes, new byte[0]),
                Genre       = Repository.GetById <Genre>(GenreId),
                Name        = Name
            };

            user.AddStore(store);

            EventBroker.Publish(new OnChangeSearchItemEvent(store));
        }