public IActionResult Index(int productTypeId)
        {
            SellerView seller = loginPersistence.PersistLogin();

            var             errors      = new List <string>();
            ProductTypeView productType = eCommerce.GetProductTypeBy(productTypeId);

            if (productType != null)
            {
                if (productType.Status == ProductTypeStatus.Locked)
                {
                    errors.Add("Product is unavailable at the moment");
                }
            }
            else
            {
                errors.Add("Could not found product type");
            }

            if (errors.Any())
            {
                ViewData[GlobalViewBagKeys.Errors] = errors;
                return(RedirectToAction("SelectProductType"));
            }

            ViewData[GlobalViewBagKeys.ECommerceService] = eCommerce;
            ProductTypeUpdateRequestView     updateRequest = eCommerce.GetProductTypeUpdateRequestBy(int.Parse(seller.Id), int.Parse(productType.Id));
            ProductTypeUpdateRequestAddModel addModel      = new ProductTypeUpdateRequestAddModel();

            if (updateRequest != null)
            {
                if (updateRequest.CategoryId != null)
                {
                    addModel.CategoryId = int.Parse(updateRequest.CategoryId);
                }
                addModel.Name          = updateRequest.Name;
                addModel.ProductTypeId = int.Parse(productType.Id);
                addModel.Descriptions  = updateRequest.Descriptions;
            }
            else
            {
                addModel.CategoryId    = int.Parse(productType.CategoryId);
                addModel.Name          = productType.Name;
                addModel.ProductTypeId = int.Parse(productType.Id);
            }
            return(View(addModel));
        }
Пример #2
0
 public IActionResult Login(string returnUrl)
 {
     if (returnUrl == null)
     {
         returnUrl = Url.HomePage();
     }
     if (loginPersistence.PersistLogin() != null)
     {
         return(Redirect(returnUrl));
     }
     return(View(new LoginViewModel
     {
         ReturnUrl = returnUrl
     }));
 }
Пример #3
0
        public async Task <IActionResult> Index(RegisterProductViewModel registerModel, IFormFile representativeImage,
                                                IList <string> keys, IList <string> values, IEnumerable <IFormFile> images)
        {
            SellerView seller = loginPersistence.PersistLogin();

            ViewData[GlobalViewBagKeys.ECommerceService] = eCommerce;
            if (ModelState.IsValid)
            {
                ICollection <string> errors = new List <string>();

                //product attributes
                var attributes = new Dictionary <string, HashSet <string> >();
                for (short i = 0; i < keys.Count; i++)
                {
                    if (!string.IsNullOrEmpty(keys[i]) && !attributes.Any(a => a.Key == keys[i]) && values[i] != null)
                    {
                        HashSet <string> separatedValues = values[i]
                                                           .Split(',', StringSplitOptions.RemoveEmptyEntries)
                                                           .ToHashSet();
                        if (separatedValues.Any())
                        {
                            attributes.Add(keys[i], separatedValues);
                        }
                    }
                }
                registerModel.AddModel.Attributes = attributes;

                //product images
                if (images.Any())
                {
                    var imagesList = new List <FileContent>();
                    foreach (IFormFile image in images)
                    {
                        using (MemoryStream memoryStream = new MemoryStream())
                        {
                            await image.CopyToAsync(memoryStream);

                            imagesList.Add(new FileContent(memoryStream.ToArray(), image.ContentType));
                        }
                    }
                    registerModel.AddModel.Images = imagesList;
                }

                //product representative image
                if (representativeImage != null)
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        await representativeImage.CopyToAsync(memoryStream);

                        registerModel.AddModel.RepresentativeImage = new FileContent(memoryStream.ToArray(), representativeImage.ContentType);
                    }
                }
                else
                {
                    errors.Add("Representative image is required");
                }

                if (errors.Any())
                {
                    return(View(registerModel));
                }

                eCommerce.RegisterProduct(int.Parse(seller.Id), registerModel.AddModel, out errors);

                if (errors.Any())
                {
                    ViewData[GlobalViewBagKeys.Errors] = errors;
                }
                else
                {
                    ICollection <string> messages = new List <string>();
                    messages.Add("Register product succeed, please wait for validation");
                    ViewData[GlobalViewBagKeys.Messages] = messages;

                    return(RedirectToAction("Product", "Seller"));
                }
            }
            return(View(registerModel));
        }
 public IViewComponentResult Invoke()
 {
     return(View(loginPersistence.PersistLogin()));
 }