Esempio n. 1
0
 public AddUserViewModel GetAddUserModel()
 {
     return(new AddUserViewModel()
     {
         Roles = SelectListItemHelper.BuildDropDownList(_userService.GetAllUserRoles())
     });
 }
Esempio n. 2
0
        public EditUserViewModel GetEditUserModel(int userId)
        {
            var user  = _userService.GetUserById(userId);
            var model = mapper.Map <UserDTO, EditUserViewModel>(user);

            model.Roles = SelectListItemHelper.BuildDropDownList(_userService.GetAllUserRoles());

            return(model);
        }
Esempio n. 3
0
        public AddProductViewModel GetAddProductsContent(AddProductViewModel model = null)
        {
            var addProductContents = _productService.GetAddProductContents();

            if (model == null)
            {
                return(new AddProductViewModel()
                {
                    Brands = SelectListItemHelper.BuildDropDownList(addProductContents.Brands),
                    Categories = SelectListItemHelper.BuildDropDownList(addProductContents.Categories),
                    Genders = SelectListItemHelper.BuildDropDownList(addProductContents.Genders),
                    ProductTypes = SelectListItemHelper.BuildDropDownList(addProductContents.ProductTypes)
                });
            }
            //TODO: Refactor this - mapper
            model.Brands       = SelectListItemHelper.BuildDropDownList(addProductContents.Brands);
            model.Categories   = SelectListItemHelper.BuildDropDownList(addProductContents.Categories);
            model.Genders      = SelectListItemHelper.BuildDropDownList(addProductContents.Genders);
            model.ProductTypes = SelectListItemHelper.BuildDropDownList(addProductContents.ProductTypes);

            return(model);
        }
Esempio n. 4
0
        //TODO: Refactor this
        public EditProductViewModel GetProductById(EditProductViewModel editProductsViewModel)
        {
            var product = _productService.GetProductById(editProductsViewModel.Id);

            var editProductViewModel = new EditProductViewModel()
            {
                Id               = editProductsViewModel.Id,
                ProductName      = product.ProductName,
                Description      = product.Description,
                Genders          = SelectListItemHelper.BuildGendersDropDownList(_genderService.GetAllGenders()),
                HeroImageCurrent = product.HeroImage,
                HeroTitle        = product.HeroTitle,
                Brands           = SelectListItemHelper.BuildDropDownList(_brandService.GetAllBrands()),
                Price            = product.Price.ToString(),
                Sizes            = mapper.Map <List <ProductSizeDTO>, List <ProductSizeViewModel> >(product.Sizes)
            };

            //TODO: Refactor this - Helper
            foreach (var gender in editProductViewModel.Genders)
            {
                if (gender.Text == product.Gender)
                {
                    gender.Selected = true;
                }
            }

            var listProductTypes = _productTypeService.GetAllProductTypes();

            foreach (var productType in listProductTypes)
            {
                editProductViewModel.ProductTypes.Add(new SelectListItem()
                {
                    Value    = productType.Id.ToString(),
                    Text     = productType.Value,
                    Selected = productType.Id == product.CategoryId
                });
            }
            //TODO: Refactor this - Helper
            foreach (var image in product.Images)
            {
                //TODO: Try put this in mapper
                if (image.Image.Length > 1)
                {
                    editProductViewModel.ImagesSrc.Add($"data:image/jpeg;base64,{Convert.ToBase64String(image.Image)}");
                }
            }
            //TODO: Refactor this - Helper
            var listCategories = _categoryService.GetAllCategories();

            foreach (var category in listCategories)
            {
                editProductViewModel.Categories.Add(new SelectListItem()
                {
                    Value    = category.Id.ToString(),
                    Text     = category.Value,
                    Selected = category.Id == product.CategoryId
                });;
            }

            return(editProductViewModel);
        }