Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(BannerEditModel model)
        {
            if (ModelState.IsValid)
            {
                var seller = await HttpContext.GetMemberAsync();

                var banner = await _bannerService.GetAsync(new BannerFilter()
                {
                    SellerId = seller.Id, BannerId = model.Id
                });

                if (banner != null)
                {
                    await _appService.PrepareBannerAsync(banner, model);

                    banner.SellerId = seller.Id;
                    await _bannerService.UpdateAsync(banner);
                    await SaveBannerImage(banner, model);

                    TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"\"{banner.Title}\" banner was updated.");
                }
            }

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Publish(long id, bool toggle)
        {
            var seller = await HttpContext.GetMemberAsync();

            var category = await _categoryService.GetAsync(new CategoryFilter()
            {
                SellerId = seller.Id, CategoryId = id
            });

            var toggleName = toggle ? "Published" : "Unpublished";

            if (category != null)
            {
                category.Published = toggle;
                await _categoryService.UpdateAsync(category);

                TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"\"{category.Name}\" category was {toggleName.ToLowerInvariant()}.");
            }
            else
            {
                TempData.AddAlert(AlertMode.Notify, AlertType.Error, $"Category does not exist.");
            }

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                string email  = model.Email;
                var    member = await _userService.FindByEmailAsync(email);

                if (member != null)
                {
                    var token = await _userService.GeneratePasswordResetTokenAsync(member);

                    var link = Url.Action(nameof(ResetPassword), "Account", new { token, email }, protocol: Request.Scheme);

                    await _messageService.SendEmailAsync(
                        messageRole : MessageRole.Notification,
                        messageType : MessageType.ResetPassword,
                        messageDisplay : "Neimart Support",
                        email : email,
                        model : new ValueTuple <User, string>(member, link));

                    TempData.AddAlert(AlertMode.Alert, AlertType.Success, "We'll send you an email within a few minutes with instructions to reset your password. If the email does not arrive soon, check your spam, junk, and bulk mail folders.",
                                      returnUrl: Url.Action(nameof(Signin), new { returnUrl }));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, $"No user registered with {email} email.");
                }
            }

            return(RedirectToAction(nameof(ForgotPassword), new { returnUrl }));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> ChangePassword(ChangePasswordModel model)
        {
            var member = await HttpContext.GetMemberAsync();

            if (HttpMethods.IsGet(Request.Method))
            {
                ModelState.Clear();
            }
            else if (HttpMethods.IsPost(Request.Method))
            {
                if (ModelState.IsValid)
                {
                    var result = await _userService.ChangePasswordAsync(member, model.CurrentPassword, model.NewPassword);

                    if (result.Succeeded)
                    {
                        TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"Password was changed.");
                    }
                    else
                    {
                        ModelState.AddIdentityResult(result);
                    }
                }
            }

            return(PartialView(model));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Publish(long id, bool toggle)
        {
            var seller = await HttpContext.GetMemberAsync();

            var product = await _productService.GetAsync(new ProductFilter()
            {
                SellerId = seller.Id, ProductId = id
            });

            var toggleName = toggle ? "Published" : "Unpublished";

            if (product != null)
            {
                product.Published = toggle;
                await _productService.UpdateAsync(product);

                TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"\"{product.Name}\" product was {toggleName.ToLowerInvariant()}.");
            }
            else
            {
                TempData.AddAlert(AlertMode.Notify, AlertType.Error, $"Product does not exist.");
            }

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> DeleteAddress(long addressId, string returnUrl)
        {
            var customer = await HttpContext.GetMemberAsync();

            var addresses = await _addressService.ListAsync(new AddressFilter { CustomerId = customer.Id });

            var address = addresses.FirstOrDefault(x => x.Id == addressId);

            if (address != null)
            {
                // Ensure the addresses does not contain the current address since it'll be deleted soon.
                addresses = addresses.Where(x => x.Id != address.Id);

                await _addressService.DeleteAsync(address);

                await _addressService.ResolveAddressTypesAsync(null, addresses);

                TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"Address was deleted.");
            }
            else
            {
                TempData.AddAlert(AlertMode.Notify, AlertType.Error, $"Address does not exist.");
            }

            return(LocalRedirect(returnUrl ?? Url.Action(nameof(Addresses))));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> SetAddressType(long addressId, AddressType addressType, bool toggle, string returnUrl)
        {
            var customer = await HttpContext.GetMemberAsync();

            var addresses = await _addressService.ListAsync(new AddressFilter { CustomerId = customer.Id });

            var address = addresses.FirstOrDefault(x => x.Id == addressId);

            if (address != null)
            {
                if (toggle)
                {
                    address.AddressTypes.Add(addressType);
                }
                else
                {
                    address.AddressTypes.Remove(addressType);
                }

                await _addressService.UpdateAsync(address);

                await _addressService.ResolveAddressTypesAsync(address, addresses);

                TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"One or more address types was changed.");
            }
            else
            {
                TempData.AddAlert(AlertMode.Notify, AlertType.Error, $"Address does not exist.");
            }

            return(LocalRedirect(returnUrl ?? Url.Action(nameof(Addresses))));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> ChangeEmail(ChangeEmailModel model, string returnUrl)
        {
            var member = await HttpContext.GetMemberAsync();

            model.OldEmail = member.Email;

            if (HttpMethods.IsGet(Request.Method))
            {
                ModelState.Clear();
            }
            else if (HttpMethods.IsPost(Request.Method))
            {
                if (ModelState.IsValid)
                {
                    var email = model.NewEmail;
                    var token = await _userService.GenerateChangeEmailTokenAsync(member, email);

                    var userId = member.Id;

                    var link = Url.Action(nameof(ChangeEmailCallback), "Account", new { token, userId, email, returnUrl }, protocol: Request.Scheme);
                    await _messageService.SendEmailAsync(
                        messageRole : MessageRole.Notification,
                        messageType : MessageType.ChangeEmail,
                        messageDisplay : "Neimart Support",
                        email : email,
                        model : new ValueTuple <User, string>(member, link));

                    TempData.AddAlert(AlertMode.Alert, AlertType.Success, "We'll send you an email within a few minutes with instructions to change your email address. If the email does not arrive soon, check your spam, junk, and bulk mail folders.");
                }
            }

            return(PartialView(model));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> EditAddress(AddressEditModel model, long addressId)
        {
            var customer = await HttpContext.GetMemberAsync();

            var addresses = await _addressService.ListAsync(new AddressFilter { CustomerId = customer.Id });

            var address = addresses.FirstOrDefault(x => x.Id == addressId);

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

            if (HttpMethods.IsGet(Request.Method))
            {
                ModelState.Clear();

                await _appService.PrepareModelAsync(model, address);
            }
            else if (HttpMethods.IsPost(Request.Method))
            {
                if (ModelState.IsValid)
                {
                    await _appService.PrepareAddressAsync(address, model);

                    await _addressService.UpdateAsync(address);

                    await _addressService.ResolveAddressTypesAsync(address, addresses);

                    TempData.AddAlert(AlertMode.Notify, AlertType.Success, "Address was updated.");
                }
            }

            return(PartialView("AddressEdit", model));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> ChangeEmailCallback(long userId, string email, string token, string returnUrl)
        {
            var member = await _userService.FindByIdAsync(userId);

            if (member != null && !string.IsNullOrWhiteSpace(email) && !string.IsNullOrWhiteSpace(token))
            {
                var result = await _userService.ChangeEmailAsync(member, email, token);

                if (result.Succeeded)
                {
                    TempData.AddAlert(AlertMode.Alert, AlertType.Success,
                                      $"You are now logged in with the email {email}." +
                                      $" You will use this email to sign into your account in the future.");

                    await _signInService.RefreshSignInAsync(member);
                }
                else
                {
                    TempData.AddAlert(AlertMode.Alert, AlertType.Error, result.Errors.Humanize());
                }
            }
            else
            {
                TempData.AddAlert(AlertMode.Alert, AlertType.Error, "Error changing email.");
            }

            return(LocalRedirect(returnUrl ?? Url.Content("~/")));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> EditReview(ReviewEditModel model, long reviewId)
        {
            var seller = await HttpContext.GetSellerAsync();

            var customer = await HttpContext.GetMemberAsync();

            var review = await _reviewService.GetAsync(new ReviewFilter { SellerId = seller.Id, CustomerId = customer.Id, ReviewId = reviewId });

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

            if (HttpMethods.IsGet(Request.Method))
            {
                ModelState.Clear();

                await _appService.PrepareModelAsync(model, review);
            }
            else if (HttpMethods.IsPost(Request.Method))
            {
                if (ModelState.IsValid)
                {
                    var existingApproved = review.Approved;
                    await _appService.PrepareReviewAsync(review, model);

                    review.Approved = existingApproved;
                    await _reviewService.UpdateAsync(review);

                    TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"\"{review.Title}\" review was updated.");
                }
            }

            return(PartialView("ReviewEdit", model));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> AddReview(ReviewEditModel model, long productId)
        {
            if (HttpMethods.IsGet(Request.Method))
            {
                ModelState.Clear();

                await _appService.PrepareModelAsync(model, null);
            }
            else if (HttpMethods.IsPost(Request.Method))
            {
                if (ModelState.IsValid)
                {
                    var seller = await HttpContext.GetSellerAsync();

                    var customer = await HttpContext.GetMemberAsync();

                    var review = new Review();
                    await _appService.PrepareReviewAsync(review, model);

                    review.ProductId  = productId;
                    review.CustomerId = customer.Id;
                    review.Approved   = true;

                    await _reviewService.CreateAsync(review);

                    TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"\"{review.Title}\" review was added.");
                }
            }

            return(PartialView("ReviewEdit", model));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Publish(long id, bool toggle)
        {
            var seller = await HttpContext.GetMemberAsync();

            var banner = await _bannerService.GetAsync(new BannerFilter()
            {
                SellerId = seller.Id, BannerId = id
            });

            var toggleName = toggle ? "Published" : "Unpublished";

            if (banner != null)
            {
                banner.Published = toggle;
                await _bannerService.UpdateAsync(banner);

                TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"\"{banner.Title}\" banner was {toggleName.ToLowerInvariant()}.");
            }
            else
            {
                TempData.AddAlert(AlertMode.Notify, AlertType.Error, $"Banner does not exist.");
            }

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Edit(CategoryEditModel model)
        {
            if (ModelState.IsValid)
            {
                var seller = await HttpContext.GetMemberAsync();

                var category = await _categoryService.GetAsync(new CategoryFilter()
                {
                    SellerId = seller.Id, CategoryId = model.Id
                });

                if (category != null)
                {
                    await _appService.PrepareCategoryAsync(category, model);

                    category.SellerId = seller.Id;
                    await _categoryService.UpdateAsync(category);
                    await SaveCategoryImage(category, model);
                    await SaveCategoryTags(category, model);

                    TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"\"{category.Name}\" category was updated.");
                }
            }

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (Email == null)
            {
                return(BadRequest());
            }

            var user = new IdentityUser()
            {
                UserName = Email,
                Email    = Email,
            };

            var identityResult = await _userManager.CreateAsync(user);

            if (identityResult.Succeeded)
            {
                _logger.LogInformation("User created a new account.");
                await SendActivationEmail(user.Email);

                TempData.AddAlert(Alert.Success($"Successfully created user {user.Email}. Have the user check his/her email to create a password"));
                return(RedirectToPage("./Index"));
            }
            else
            {
                TempData.AddAlert(Alert.Error($"Failed to create user. {identityResult.ToString()}"));
                return(Page());
            }
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> ChangePhoneNumber(ChangePhoneNumberModel model)
        {
            var member = await HttpContext.GetMemberAsync();

            if (HttpMethods.IsGet(Request.Method))
            {
                ModelState.Clear();
            }
            else if (HttpMethods.IsPost(Request.Method))
            {
                if (ModelState.IsValid)
                {
                    var result = await _userService.SetPhoneNumberAsync(member, model.NewPhoneNumber);

                    if (result.Succeeded)
                    {
                        TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"Phone number was set to {_appSettings.FormatPhoneNumber(model.NewPhoneNumber)}.");
                    }
                    else
                    {
                        ModelState.AddIdentityResult(result);
                    }
                }
            }

            return(PartialView(model));
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> Edit(ProductEditModel model)
        {
            if (ModelState.IsValid)
            {
                var seller = await HttpContext.GetMemberAsync();

                var product = await _productService.GetAsync(new ProductFilter()
                {
                    SellerId = seller.Id, ProductId = model.Id
                });

                if (product != null)
                {
                    await _appService.PrepareProductAsync(product, model);

                    product.SellerId = seller.Id;
                    await _productService.UpdateAsync(product);

                    await SaveProductImages(product, model);
                    await SaveProductDocument(product, model);
                    await SaveProductTags(product, model);

                    TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"\"{product.Name}\" product was updated.");
                }
            }

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> Approve(long id, bool toggle)
        {
            var seller = await HttpContext.GetMemberAsync();

            var review = await _reviewService.GetAsync(new ReviewFilter()
            {
                SellerId = seller.Id, ReviewId = id
            });

            var toggleName = toggle ? "Approved" : "Rejected";

            if (review != null)
            {
                review.Approved = toggle;
                await _reviewService.UpdateAsync(review);

                TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"\"{review.Title}\" review was {toggleName.ToLowerInvariant()}.");
            }
            else
            {
                TempData.AddAlert(AlertMode.Notify, AlertType.Error, $"Review does not exist.");
            }

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> EditPayment(PaymentEditModel model)
        {
            var user = await HttpContext.GetMemberAsync();

            var issuers = await _paymentProcessor.GetIssuersAsync();

            model.MobileIssuerOptions.AddRange(SelectListHelper.GetSelectList(elements: issuers.Where(x => x.Mode == PaymentMode.Mobile), x => new SelectListItem <PaymentIssuer>(x.Name, x.Code)));
            model.BankIssuerOptions.AddRange(SelectListHelper.GetSelectList(elements: issuers.Where(x => x.Mode == PaymentMode.Bank), x => new SelectListItem <PaymentIssuer>(x.Name, x.Code)));

            if (HttpMethods.IsGet(Request.Method))
            {
                ModelState.Clear();

                if (model.Mode == PaymentMode.Mobile)
                {
                    model.MobileIssuer = user.MobileIssuer;
                    model.MobileNumber = user.MobileNumber;
                }
                else if (model.Mode == PaymentMode.Bank)
                {
                    model.BankIssuer = user.BankIssuer;
                    model.BankNumber = user.BankNumber;
                }
            }
            else if (HttpMethods.IsPost(Request.Method))
            {
                if (ModelState.IsValid)
                {
                    if (model.Mode == PaymentMode.Mobile)
                    {
                        user.MobileIssuer = model.MobileIssuer;
                        user.MobileNumber = model.MobileNumber;
                    }
                    else if (model.Mode == PaymentMode.Bank)
                    {
                        user.BankIssuer = model.BankIssuer;
                        user.BankNumber = model.BankNumber;
                    }

                    var result = await _userService.UpdateAsync(user);

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

            return(PartialView(nameof(EditPayment), model));
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> Signin(SignInModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var member = await _userService.FindByEmailAsync(model.Email);

                if (member != null)
                {
                    var result = await _signInService.PasswordSignInAsync(member, model.Password, isPersistent : false, lockoutOnFailure : true);

                    if (result.Succeeded)
                    {
                        return(LocalRedirect(returnUrl ?? Url.Action("Index", "Home", new { area = "Portal" })));
                    }
                    else if (result.IsLockedOut)
                    {
                        return(RedirectToAction(nameof(Lockout), new { returnUrl }));
                    }
                    else if (result.RequiresTwoFactor)
                    {
                        return(RedirectToAction(nameof(Signin2fa), new { returnUrl }));
                    }
                    else if (result.IsNotAllowed)
                    {
                        if (!await _userService.IsEmailConfirmedAsync(member))
                        {
                            var token = await _userService.GenerateEmailConfirmationTokenAsync(member);

                            var link = Url.Action(nameof(VerifyEmail), "Account", new { userId = member.Id, token, returnUrl }, protocol: Request.Scheme);

                            await _messageService.SendEmailAsync(
                                messageRole : MessageRole.Notification,
                                messageType : MessageType.VerifyEmail,
                                messageDisplay : "Neimart Support",
                                email : member.Email,
                                model : new ValueTuple <User, string>(member, link));

                            TempData.AddAlert(AlertMode.Alert, AlertType.Info, $"We'll send you an email within a few minutes with instructions to verify your email address. If the email does not arrive soon, check your spam, junk, and bulk mail folders.", title: "Email Verification Required");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "We couldn't sign you in. If you forgot your password, you can request for a password reset.");
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "We couldn't sign you in. If you don't have an account yet, you should create one.");
                }
            }

            return(RedirectToAction(nameof(Signin), new { returnUrl }));
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> Contact(ContactModel model)
        {
            if (ModelState.IsValid)
            {
                await _messageService.SendEmailAsync(
                    messageRole : MessageRole.Info,
                    messageType : MessageType.CompanyContact,
                    messageDisplay : "Neimart Support",
                    email : _appSettings.Company.InfoEmail, model);

                TempData.AddAlert(AlertMode.Alert, AlertType.Success, "Your message has been sent. We'll contact you shortly.");
            }

            return(RedirectToAction());
        }
Ejemplo n.º 22
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.º 23
0
        public async Task <IActionResult> Add(BannerEditModel model, BannerSize size)
        {
            if (ModelState.IsValid)
            {
                var seller = await HttpContext.GetMemberAsync();

                var banner = new Banner();
                await _appService.PrepareBannerAsync(banner, model);

                banner.SellerId = seller.Id;
                await _bannerService.CreateAsync(banner);
                await SaveBannerImage(banner, model);

                TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"\"{banner.Title}\" banner was added.");
            }

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> SetStoreAccess(long id, StoreAccess access)
        {
            var user = await _userService.FindByIdAsync(id);

            if (user != null)
            {
                user.StoreAccess = access;
                await _userService.UpdateAsync(user);

                TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"\"{user.StoreName}\" store access was mark as {user.StoreAccess.GetEnumText()}.");
            }
            else
            {
                TempData.AddAlert(AlertMode.Notify, AlertType.Error, $"User does not exist.");
            }

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            IdentityUser = await _userManager.FindByIdAsync(id);

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

            await _userManager.DeleteAsync(IdentityUser);

            TempData.AddAlert(Alert.Success($"Successfully Deleted User {IdentityUser.Email}"));
            return(RedirectToPage("Index"));
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> Add(CategoryEditModel model)
        {
            if (ModelState.IsValid)
            {
                var seller = await HttpContext.GetMemberAsync();

                var category = new Category();
                await _appService.PrepareCategoryAsync(category, model);

                category.SellerId = seller.Id;
                await _categoryService.CreateAsync(category);
                await SaveCategoryImage(category, model);
                await SaveCategoryTags(category, model);

                TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"\"{category.Name}\" category was added.");
            }

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 27
0
        public async Task <IActionResult> Contact(ContactModel model)
        {
            if (ModelState.IsValid)
            {
                var seller = await HttpContext.GetSellerAsync();

                await _messageService.SendEmailAsync(
                    messageRole : MessageRole.Notification,
                    messageType : MessageType.StoreContact,
                    messageDisplay : $"{seller.StoreName} via Neimart",
                    email : seller.Email,
                    subject : model.Subject,
                    model : (seller, model));

                TempData.AddAlert(AlertMode.Notify, AlertType.Success, "Thank you for contacting us. We will reply as soon as possible.");
            }

            return(RedirectToAction());
        }
Ejemplo n.º 28
0
        public async Task <IActionResult> AddAddress(AddressEditModel model, AddressType?addressType)
        {
            var customer = await HttpContext.GetMemberAsync();

            if (HttpMethods.IsGet(Request.Method))
            {
                ModelState.Clear();

                if (addressType != null)
                {
                    model.AddressTypes.Add(addressType.Value);
                }

                // Set predefined values when adding a new address.
                model.FirstName    = customer.FirstName;
                model.LastName     = customer.LastName;
                model.Email        = customer.Email;
                model.PhoneNumber  = customer.PhoneNumber;
                model.Organization = customer.StoreName;

                await _appService.PrepareModelAsync(model, null);
            }
            else if (HttpMethods.IsPost(Request.Method))
            {
                if (ModelState.IsValid)
                {
                    var addresses = await _addressService.ListAsync(new AddressFilter { CustomerId = customer.Id });

                    var address = new Address();
                    await _appService.PrepareAddressAsync(address, model);

                    address.CustomerId = customer.Id;
                    await _addressService.CreateAsync(address);

                    await _addressService.ResolveAddressTypesAsync(address, addresses);

                    TempData.AddAlert(AlertMode.Notify, AlertType.Success, "Address was added.");
                }
            }

            return(PartialView("AddressEdit", model));
        }
Ejemplo n.º 29
0
        public async Task <IActionResult> Preview(long id)
        {
            var seller = await HttpContext.GetMemberAsync();

            var product = await _productService.GetAsync(new ProductFilter()
            {
                SellerId = seller.Id, ProductId = id
            });

            if (product != null)
            {
                return(RedirectToAction("Products", "Store", new { area = string.Empty, storeSlug = seller.StoreSlug, slug = product.Slug }));
            }
            else
            {
                TempData.AddAlert(AlertMode.Notify, AlertType.Error, $"Product does not exist.");
            }

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 30
0
        public async Task <IActionResult> DeleteReview(long reviewId, string returnUrl)
        {
            var seller = await HttpContext.GetSellerAsync();

            var customer = await HttpContext.GetMemberAsync();

            var review = await _reviewService.GetAsync(new ReviewFilter { SellerId = seller.Id, CustomerId = customer.Id, ReviewId = reviewId });

            if (review != null)
            {
                await _reviewService.DeleteAsync(review);

                TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"\"{review.Title}\" review was deleted.");
            }
            else
            {
                TempData.AddAlert(AlertMode.Notify, AlertType.Error, $"Review does not exist.");
            }

            return(LocalRedirect(returnUrl ?? Url.Action(nameof(Reviews))));
        }