Ejemplo n.º 1
0
        public Task PrepareStoreAsync(User user, StoreEditModel model)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            user = _mapper.Map(model, user);

            user.StoreCategory = model.StoreCategorySelections.MergeEnums();

            user.StoreSlug = SanitizerHelper.GenerateSlug(model.StoreSlug);

            user.AboutNote   = SanitizerHelper.SanitizeHtml(model.AboutNote);
            user.TermsNote   = SanitizerHelper.SanitizeHtml(model.TermsNote);
            user.PrivacyNote = SanitizerHelper.SanitizeHtml(model.PrivacyNote);
            user.ReturnsNote = SanitizerHelper.SanitizeHtml(model.ReturnsNote);
            user.ReviewsNote = SanitizerHelper.SanitizeHtml(model.ReviewsNote);


            user.FacebookLink   = SanitizerHelper.AppendUrlScheme(model.FacebookLink);
            user.TwitterLink    = SanitizerHelper.AppendUrlScheme(model.TwitterLink);
            user.YoutubeLink    = SanitizerHelper.AppendUrlScheme(model.YoutubeLink);
            user.InstagramLink  = SanitizerHelper.AppendUrlScheme(model.InstagramLink);
            user.LinkedInLink   = SanitizerHelper.AppendUrlScheme(model.LinkedInLink);
            user.PinterestLink  = SanitizerHelper.AppendUrlScheme(model.PinterestLink);
            user.WhatsAppNumber = SanitizerHelper.ExtractPhoneNumber(model.WhatsAppNumber);
            user.MapLink        = SanitizerHelper.AppendUrlScheme(model.MapLink);

            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> EditStore()
        {
            var seller = await HttpContext.GetMemberAsync();

            var model = new StoreEditModel();
            await _appService.PrepareModelAsync(model, seller);

            return(View(model));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> EditStore(StoreEditModel model)
        {
            if (ModelState.IsValid)
            {
                var seller = await HttpContext.GetMemberAsync();

                var firstStoreSetup = false;

                await _appService.PrepareStoreAsync(seller, model);

                if (!seller.StoreSetup)
                {
                    seller.StoreSetup = true;
                    firstStoreSetup   = true;
                }

                var result = await _userService.CheckStoreSlugAsync(seller);

                result = result.Succeeded ? await _userService.UpdateAsync(seller) : result;

                if (result.Succeeded)
                {
                    if (firstStoreSetup)
                    {
                        await _messageService.SendEmailAsync(
                            messageRole : MessageRole.Notification,
                            messageType : MessageType.CompanyWelcome,
                            messageDisplay : "Neimart",
                            email : seller.Email,
                            subject : "You have just started a new business",
                            model : new ValueTuple <User, object>(seller, null));
                    }

                    await SaveStoreLogoAsync(seller, model);
                    await SaveStoreDocumentAsync(seller, model);

                    TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"Store was updated.");
                }
                else
                {
                    ModelState.AddIdentityResult(result);
                }
            }

            return(RedirectToAction());
        }
Ejemplo n.º 4
0
        private async Task SaveStoreDocumentAsync(User user, StoreEditModel model)
        {
            // The user is already approved and isn't allowed to update his store document.
            if (user.StoreAccess == StoreAccess.Approved)
            {
                return;
            }

            var fileClient     = HttpContext.RequestServices.GetRequiredService <IFileClient>();
            var imageProcessor = HttpContext.RequestServices.GetRequiredService <IImageProcessor>();

            await _appService.PrepareMediaAsync(new[] { user.StoreDocument }, new[] { model.StoreDocument },
                                                createMedia : async(document) =>
            {
                document.DirectoryName = user.Id.ToString();

                var source = await fileClient.GetAsync(document.DirectoryName, document.FileName);

                if (source != null)
                {
                    document.FileSize = source.Length;

                    await _mediaService.CreateAsync(document);

                    user.StoreDocumentId = document.Id;
                    await _userService.UpdateAsync(user);
                }
            },
                                                updateMedia : async(document) =>
            {
                await _mediaService.UpdateAsync(document);
            },
                                                deleteMedia : async(document) =>
            {
                user.StoreDocumentId = null;
                user.StoreDocument   = null;

                await _userService.UpdateAsync(user);
                await _mediaService.DeleteAsync(document);
            });
        }
Ejemplo n.º 5
0
        private async Task SaveStoreLogoAsync(User user, StoreEditModel model)
        {
            var fileClient     = HttpContext.RequestServices.GetRequiredService <IFileClient>();
            var imageProcessor = HttpContext.RequestServices.GetRequiredService <IImageProcessor>();

            await _appService.PrepareMediaAsync(new[] { user.StoreLogo }, new[] { model.StoreLogo },
                                                createMedia : async(image) =>
            {
                image.DirectoryName = user.Id.ToString();

                var source = await fileClient.GetAsync(image.DirectoryName, image.FileName);

                if (source != null)
                {
                    var(imageWidth, imageHeight) = await imageProcessor.GetImageSizeAsync(source);

                    image.Width    = imageWidth;
                    image.Height   = imageHeight;
                    image.FileSize = source.Length;

                    await _mediaService.CreateAsync(image);

                    user.StoreLogoId = image.Id;
                    await _userService.UpdateAsync(user);
                }
            },
                                                updateMedia : async(media) =>
            {
                await _mediaService.UpdateAsync(media);
            },
                                                deleteMedia : async(media) =>
            {
                user.StoreLogoId = null;
                user.StoreLogo   = null;

                await _userService.UpdateAsync(user);
                await _mediaService.DeleteAsync(media);
            });
        }
Ejemplo n.º 6
0
        public Task PrepareModelAsync(StoreEditModel model, User user)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            model = _mapper.Map(user, model);

            model.StoreDeliveryRequiredOptions.AddRange(SelectListHelper.GetBoolSelectList("Required", "Not Required", selectedBool: model.StoreDeliveryRequired));
            model.StoreStatusOptions.AddRange(SelectListHelper.GetEnumSelectList <StoreStatus>(selectedEnum: model.StoreStatus));

            model.StoreThemeModeOptions.AddRange(SelectListHelper.GetEnumSelectList <ThemeMode>(selectedEnum: model.StoreThemeMode));
            model.StoreThemeStyleOptions.AddRange(SelectListHelper.GetEnumSelectList <ThemeStyle>(selectedEnum: model.StoreThemeStyle));

            model.StoreCategorySelections.AddRange(user.StoreCategory.ExpandEnum());
            model.StoreCategoryOptions.AddRange(SelectListHelper.GetEnumSelectList <StoreCategory>(selectedEnum: user.StoreCategory));

            return(Task.CompletedTask);
        }