public async Task <IActionResult> Edit(EditContentTypeViewModel viewModel) { SpeedWagonContent contentType = await this._speedWagon.ContentTypeService.Get(viewModel.Name); if (!ModelState.IsValid) { IEnumerable <SpeedWagonContent> editors = await this._speedWagon.EditorService.List(); IEnumerable <SpeedWagonContent> contentTypes = await this._speedWagon.ContentTypeService.List(); viewModel.ContentType = contentType; viewModel.Root = contentType.GetValue <bool>("Root"); viewModel.Children = contentType.GetValue <string[]>("Children"); viewModel.Name = contentType.Name; viewModel.Url = contentType.RelativeUrl; viewModel.AvailableContentTypes = SelectListHelper.GetSelectList(contentTypes); viewModel.AvailableEditors = SelectListHelper.GetSelectList(editors); viewModel.Editors = this._speedWagon.ContentTypeService.GetEditors(contentType); return(View(viewModel)); } contentType.Content["Root"] = viewModel.Root; contentType.Content["Children"] = viewModel.Children; this._speedWagon.ContentTypeService.Save(contentType, User.Identity.Name.MaskEmail()); return(RedirectToAction("Edit", new { url = contentType.Name, operation = "edited" })); }
public async Task <IActionResult> List(string url = null) { SpeedWagonContent contentRoot = await this._speedWagon.WebContentService.GetContent(url); IEnumerable <SpeedWagonContent> contents = await this._speedWagon.ContentService.Children(contentRoot); contents = contents.OrderBy(x => x.SortOrder); IEnumerable <SpeedWagonContent> contentTypes = null; if (string.IsNullOrEmpty(url) || url == "/content") { contentTypes = await this._speedWagon.ContentTypeService.ListRootTypes(); } else { contentTypes = await this._speedWagon.ContentTypeService.ListAllowedChildren(contentRoot.Type); } IList <SelectListItem> contentTypeSelct = SelectListHelper.GetSelectList(contentTypes); ContentViewModel viewModel = new ContentViewModel(); viewModel.AvailableContentTypes = contentTypeSelct; viewModel.Content = contentRoot; viewModel.Contents = contents; viewModel.ContentService = this._speedWagon.ContentService; return(View("~/Views/SpeedWagon/Content/List.cshtml", viewModel)); }
public async Task <IViewComponentResult> InvokeAsync() { var seller = await HttpContext.GetSellerAsync(); var customer = await HttpContext.GetMemberAsync(); var carts = (await _cartService.ListAsync(new CartFilter { SellerId = seller.Id, CustomerId = customer?.Id ?? 0 })); // Ensure all carts are validated before evaluation. carts = carts.Where(x => _cartService.Validate(x).Success); var model = new StoreHeaderModel { CartListEvaluation = await _cartService.EvaluateAsync(carts.Where(x => x.Type == CartType.Cart)), WishlistEvaluation = await _cartService.EvaluateAsync(carts.Where(x => x.Type == CartType.Wishlist)) }; var isProductsRoute = string.Equals(Request.RouteValues["action"]?.ToString(), "Products", StringComparison.InvariantCultureIgnoreCase); var slug = isProductsRoute ? Request.Query["search"].ToString() : null; var categories = await _categoryService.ListAsync(new CategoryFilter { Published = true, SellerId = seller.Id }); model.CategoryOptions.AddRange(SelectListHelper.GetSelectList(categories, x => { return(new SelectListItem <Category>(text: x.Name, value: x.Slug, x.Slug == slug || x.Tags.Any(tag => tag.Slug == slug))); }, defaultText: "Products", defaultSelected: isProductsRoute && string.IsNullOrWhiteSpace(slug))); return(View(model)); }
public async Task PrepareModelAsync(CategoryEditModel model, Category category, User seller) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (category != null) { model = _mapper.Map(category, model); model.TagNames.AddRange(category.Tags.Select(x => x.Name)); } else { model.Published = true; } var tagNames = (await _tagService.ListAsync(new TagFilter() { SellerId = seller.Id })).Select(x => x.Name).Distinct(); model.TagOptions.AddRange(SelectListHelper.GetSelectList(tagNames, x => new SelectListItem <string>(text: x, value: x))); var icons = await GenerateFa5IconsAsync(); model.IconOptions.AddRange(SelectListHelper.GetSelectList(icons, x => new SelectListItem <string>(text: x.Humanize(LetterCasing.Title), value: x, selected: x == model.Icon), defaultText: "No Icon")); }
public Task PrepareModelAsync(ReviewListModel model, IPageable <Review> reviews) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (reviews == null) { throw new ArgumentNullException(nameof(reviews)); } foreach (var review in reviews) { var reviewModel = new ReviewModel { Review = review }; model.Items.Add(reviewModel); } model.ApprovedOptions.AddRange(SelectListHelper.GetBoolSelectList("Approved", "Rejected", selectedBool: model.Filter.Approved, defaultText: "All")); model.RatingOptions.AddRange(SelectListHelper.GetSelectList(Enumerable.Range(1, 5).Reverse(), (x) => new SelectListItem <int>(text: $"{"star".ToQuantity(x)}", value: x.ToString(), selected: x == model.Filter.Rating), defaultText: "All")); model.Page = reviews.Page; model.PageSize = reviews.PageSize; model.PageFrom = reviews.PageFrom; model.PageTo = reviews.PageTo; model.TotalPages = reviews.TotalPages; model.TotalItems = reviews.TotalItems; return(Task.CompletedTask); }
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)); }
public async Task <IActionResult> List() { ContentTypeViewModel viewModel = new ContentTypeViewModel(); viewModel.ContentTypes = await this._speedWagon.ContentTypeService.List(); IEnumerable <SpeedWagonContent> contentTypes = await this._speedWagon.ContentTypeService.List(); viewModel.AvailableContentTypes = SelectListHelper.GetSelectList(contentTypes, true); return(View("~/Views/SpeedWagon/ContentType/List.cshtml", viewModel)); }
public async Task <IActionResult> EditProperty(string name, string property) { SpeedWagonContent contentType = await this._speedWagon.ContentTypeService.Get(name); ContentTypeEditor[] properties = this._speedWagon.ContentTypeService.GetEditors(contentType); IEnumerable <SpeedWagonContent> editors = await this._speedWagon.EditorService.List(); ContentTypeEditor prop = properties.FirstOrDefault(x => x.Name == property); EditProperty model = new EditProperty(); model.ContentTypeName = contentType.Name; model.Property = prop; model.AvailableEditors = SelectListHelper.GetSelectList(editors); return(View("~/Views/SpeedWagon/ContentType/EditProperty.cshtml", model)); }
public async Task PrepareModelAsync(CartListModel model, IPageable <Cart> carts) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (carts == null) { throw new ArgumentNullException(nameof(carts)); } foreach (var cart in carts) { var cartModel = _mapper.Map(cart, new CartModel()); cartModel.ProductModel = new ProductModel(); await PrepareModelAsync(cartModel.ProductModel, cart.Product); cartModel.Evaluation = await _cartService.EvaluateAsync(cart); int minQuantity = 1; int maxQuantity = _appSettings.QuantityMaxValue; int existingQuantity = cart.Quantity; var quantities = Enumerable.Range(minQuantity, maxQuantity); cartModel.QuantityOptions.AddRange(SelectListHelper.GetSelectList(quantities, (newQuantity) => { int remainingQuantity = newQuantity - existingQuantity; bool selectedQuantity = (newQuantity == existingQuantity); return(new SelectListItem <int>(text: newQuantity.ToString(), value: remainingQuantity.ToString(), selected: selectedQuantity)); })); model.Items.Add(cartModel); } model.CartListEvaluation = await _cartService.EvaluateAsync(carts); model.Page = carts.Page; model.PageSize = carts.PageSize; model.PageFrom = carts.PageFrom; model.PageTo = carts.PageTo; model.TotalPages = carts.TotalPages; model.TotalItems = carts.TotalItems; }
static void Main(string[] args) { var t = new List <Product>() { new Product() { Id = 1, Name = "Pepper" }, new Product() { Id = 2, Name = "Watermelon" }, new Product() { Id = 2, Name = "Grape" }, }; var selectList = SelectListHelper.GetSelectList(t, "Id", "Name", true, "Product", "-1"); var selectList2 = t.ToSelectList("Id", "Name", true, "Seçelim"); }
public async Task <IActionResult> AddProperty(EditContentTypeViewModel viewModel) { SpeedWagonContent contentType = await this._speedWagon.ContentTypeService.Get(viewModel.Url); if (!ModelState.IsValid) { IEnumerable <SpeedWagonContent> editors = await this._speedWagon.EditorService.List(); viewModel.ContentType = contentType; viewModel.Name = contentType.Name; viewModel.AvailableEditors = SelectListHelper.GetSelectList(editors); viewModel.Editors = this._speedWagon.ContentTypeService.GetEditors(contentType); return(View(viewModel)); } this._speedWagon.ContentTypeService.AddEditor(contentType, viewModel.ContentTypeEditor); this._speedWagon.ContentTypeService.Save(contentType, User.Identity.Name.MaskEmail()); return(RedirectToAction("Edit", new { url = viewModel.Url })); }
public async Task <IActionResult> Edit(string url, string operation = null) { SpeedWagonContent contentType = await this._speedWagon.ContentTypeService.Get(url); IEnumerable <SpeedWagonContent> editors = await this._speedWagon.EditorService.List(); IEnumerable <SpeedWagonContent> contentTypes = await this._speedWagon.ContentTypeService.List(); EditContentTypeViewModel viewModel = new EditContentTypeViewModel(); viewModel.Operation = operation; viewModel.ContentType = contentType; viewModel.Root = contentType.GetValue <bool>("Root"); viewModel.Children = contentType.GetValue <string[]>("Children"); viewModel.Name = contentType.Name; viewModel.Url = url; viewModel.AvailableContentTypes = SelectListHelper.GetSelectList(contentTypes); viewModel.AvailableEditors = SelectListHelper.GetSelectList(editors); viewModel.Editors = this._speedWagon.ContentTypeService.GetEditors(contentType); return(View("~/Views/SpeedWagon/ContentType/Edit.cshtml", viewModel)); }
public async Task <IActionResult> Add(ContentViewModel viewModel) { if (!ModelState.IsValid) { SpeedWagonContent contentRoot = await this._speedWagon.WebContentService.GetContent(viewModel.Parent); IEnumerable <SpeedWagonContent> contents = await this._speedWagon.ContentService.Children(contentRoot); IEnumerable <SpeedWagonContent> contentTypes = await this._speedWagon.ContentTypeService.List(); IList <SelectListItem> contentTypeSelct = SelectListHelper.GetSelectList(contentTypes); viewModel.AvailableContentTypes = contentTypeSelct; viewModel.Content = contentRoot; viewModel.Contents = contents; viewModel.ContentService = this._speedWagon.ContentService; return(View("~/Views/SpeedWagon/Content/List.cshtml", viewModel)); } this._speedWagon.WebContentService.Add(viewModel.Parent, viewModel.Name, viewModel.Type, User.Identity.Name.MaskEmail()); return(RedirectToAction("List", "SpeedWagonContent", new { url = viewModel.Parent })); }
public async Task PrepareModelAsync(ProductEditModel model, Product product, User seller) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (seller == null) { throw new ArgumentNullException(nameof(seller)); } if (product != null) { model = _mapper.Map(product, model); model.Images = product.Images.ToList(); model.TagNames.AddRange(product.Tags.Select(x => x.Name)); } else { model.Published = true; model.Stock = ProductStock.InStock; } model.StockOptions.AddRange(SelectListHelper.GetEnumSelectList <ProductStock>(selectedEnum: model.Stock)); var categoryNames = (await _categoryService.ListAsync(new CategoryFilter { SellerId = seller.Id })).Select(x => x.Name).Distinct(); var tagNames = (await _tagService.ListAsync(new TagFilter { SellerId = seller.Id })).Select(x => x.Name).Distinct(); tagNames = categoryNames.Concat(tagNames).Distinct(StringComparer.InvariantCultureIgnoreCase); model.TagOptions.AddRange(SelectListHelper.GetSelectList(tagNames, x => new SelectListItem <string>(text: x, value: x))); }
public async Task <IActionResult> CashOut(CashOutModel model) { var member = 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.MobileIssuer = member.MobileIssuer; model.MobileNumber = member.MobileNumber; model.BankIssuerOptions.AddRange(SelectListHelper.GetSelectList(elements: issuers.Where(x => x.Mode == PaymentMode.Bank), x => new SelectListItem <PaymentIssuer>(x.Name, x.Code))); model.BankIssuer = member.BankIssuer; model.BankNumber = member.BankNumber; model.Fee = Math.Round(((_appSettings.PaymentRate * 100) * model.Amount) / 100, 2, MidpointRounding.AwayFromZero); if (HttpMethods.IsGet(Request.Method)) { ModelState.Clear(); } else if (HttpMethods.IsPost(Request.Method)) { if (ModelState.IsValid) { var canWithdraw = _userService.CanWithdraw(member, model.Amount + model.Fee); if (canWithdraw.Success) { if (!Request.IsCallBack()) { ViewData["Persistent"] = true; } else { var transaction = new Transaction { Title = $"Payment for Withdrawal.", Description = $"Payment for Withdrawal.", Logo = Url.ContentLink(Url.Content("~/img/logo.png")), MemberId = member.Id, Reference = model.Reference, AccountName = member.FullName, AccountEmail = member.Email, AccountNumber = model.AccountNumber, AccountBalance = member.Balance, TransactionCode = await _paymentProcessor.GenerateTransactionCodeAsync(), AuthorizationCode = await _paymentProcessor.GetAuthorizationCodeAsync(), Issuer = model.Issuer, Mode = model.Mode, Processor = TransactionProcessor.External, Amount = model.Amount, Fee = model.Fee, IpAddress = await HttpContext.GetIpAddressAsync(), UserAgent = Request.Headers["User-Agent"], Type = TransactionType.Withdrawal, }; await _paymentProcessor.ProcessAsync(transaction); if (transaction.Status == TransactionStatus.Pending) { await _paymentProcessor.VerifyAsync(transaction); } if (transaction.Status == TransactionStatus.Succeeded) { await _transactionService.CreateAsync(transaction); await _userService.WithdrawAsync(member, transaction.Amount + transaction.Fee); TempData.AddAlert(AlertMode.Notify, AlertType.Success, "Payment successful!"); } else { ModelState.AddModelError(string.Empty, "Unable to process payment."); } } } else { ModelState.AddModelError(string.Empty, canWithdraw.Message); } } } return(PartialView(model)); }
public async Task PrepareModelAsync(ProductListModel model, IPageable <Product> products, User seller, User customer = null) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (products == null) { throw new ArgumentNullException(nameof(products)); } foreach (var product in products) { var productModel = new ProductModel(); await PrepareModelAsync(productModel, product); if (customer != null) { productModel.IsAddedToCart = await _cartService.GetQuery(new CartFilter { CustomerId = customer.Id, SellerId = seller.Id, ProductId = product.Id, Type = CartType.Cart }).AnyAsync(); productModel.IsAddedToWishlist = await _cartService.GetQuery(new CartFilter { CustomerId = customer.Id, SellerId = seller.Id, ProductId = product.Id, Type = CartType.Wishlist }).AnyAsync(); } // NOTE: "StoreController.cs" with the line number 299 for code changes. productModel.ReviewEvaluation = await _reviewService.EvaluateAsync(new ReviewFilter { Approved = true, SellerId = seller.Id, ProductId = product.Id }); model.Items.Add(productModel); } model.LowestMinPrice = 0; model.HighestMaxPrice = (int)Math.Min(_appSettings.CurrencyMaxValue, int.MaxValue); model.SortOptions.AddRange(SelectListHelper.GetEnumSelectList(selectedEnum: model.Filter.Sort, defaultText: "Any")); model.StockOptions.AddRange(SelectListHelper.GetEnumSelectList(selectedEnum: model.Filter.Stock, defaultText: "All")); model.PublishedOptions.AddRange(SelectListHelper.GetBoolSelectList("Published", "Unpublished", selectedBool: model.Filter.Published, defaultText: "All")); model.RatingOptions.AddRange(SelectListHelper.GetSelectList(Enumerable.Range(1, 4).Reverse(), (x) => new SelectListItem <int>(text: $"{"star".ToQuantity(x)} or more", value: x.ToString(), selected: x == model.Filter.Rating))); model.DiscountOptions.AddRange(SelectListHelper.GetSelectList(Enumerable.Range(1, 4).Select(x => x * 20).Reverse(), (x) => new SelectListItem <int>(text: $"{x}% or more", value: x.ToString(), selected: x == model.Filter.Discount))); var categories = await _categoryService.ListAsync(new CategoryFilter() { SellerId = seller.Id, Published = true }); model.CategoryOptions.AddRange(SelectListHelper.GetSelectList(categories, x => new SelectListItem <Category>(text: x.Name, value: x.Slug, x.Slug == model.Filter.Search), defaultText: "All")); model.Page = products.Page; model.PageSize = products.PageSize; model.PageFrom = products.PageFrom; model.PageTo = products.PageTo; model.TotalPages = products.TotalPages; model.TotalItems = products.TotalItems; }