public ActionResult Create()
        {
            var model = new ProductSaveVM()
            {
                ColorList = _productService.GetProductColors().Select(o => new ColorOptionVM(o)).ToList(),
            };

            return(View("Save", model));
        }
Exemplo n.º 2
0
        public IResult AddProduct(ProductSaveVM product)
        {
            _productDal.Add(new Product()
            {
                ProductName = product.ProductName,
                CategoryId  = product.CategoryId
            });

            return(new SuccessResult());
        }
Exemplo n.º 3
0
 /// <summary>
 /// Add a produt to the system
 /// </summary>
 /// <param name="modelVM"></param>
 /// <returns>type of int with the newly inserted produt ID</returns>
 public async Task<int> AddProduct(ProductSaveVM modelVM)
 {
     try
     {
         return await StdRepo.ExcuteStoredProcedureToSave<ProductSaveVM>(GlobalSPNames.AddProductSPName, modelVM);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 4
0
        public IDataResult <ProductSaveVM> InitializeProduct()
        {
            var tempResult = new ProductSaveVM();

            tempResult.CategoryList = _categoryDal.GetList().Select(x => new SelectModel()
            {
                Text  = x.CategoryName,
                Value = x.CategoryId.ToString()
            }).ToList();

            return(new SuccessDataResult <ProductSaveVM>(tempResult));
        }
        /// <summary>
        /// Build product DTO to be sent to the service layer -> repo layer
        /// </summary>
        /// <param name="vm">vm from create/edit page</param>
        /// <param name="edit">determines if this is a new product or existing (set on the controller)</param>
        /// <returns>product dto</returns>
        private Product BuildProductDTO(ProductSaveVM vm, bool edit = false)
        {
            var dto = new Product
            {
                Id    = !edit ? 0 : vm.Id,
                Name  = vm.Name,
                Color = _productService.GetColorName(vm.Color),
                Price = vm.Price,
                Slug  = !edit?Guid.NewGuid().ToString() : string.Empty  //slug is never updated on an edit so setting to empty
            };

            return(dto);
        }
Exemplo n.º 6
0
 public async Task <HttpResponseMessage> SaveProduct(ProductSaveVM modelVM, int action)
 {
     try
     {
         string username      = RequestContext.Principal.Identity.Name;
         string clientAddress = HttpContext.Current.Request.UserHostAddress;
         return(Request.CreateResponse(HttpStatusCode.OK, await corepo.AddProduct(modelVM)));
     }
     catch (Exception ex)
     {
         LogHelper.WriteLog(HttpContext.Current.Request, ex, RequestContext.Principal.Identity.Name);
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
     }
 }
        public async Task <IActionResult> Edit(string slug)
        {
            var product = await _productService.GetProduct(slug);

            if (product != null)
            {
                var model = new ProductSaveVM(product)
                {
                    Color     = _productService.GetColorId(product.Color),
                    ColorList = _productService.GetProductColors().Select(o => new ColorOptionVM(o)).ToList(),
                };

                return(View("Save", model));
            }

            return(RedirectToAction(nameof(Index))); //redirect to products page if product does not exist
        }
        public async Task <IActionResult> Create([FromForm] ProductSaveVM vm)
        {
            if (ModelState.IsValid)
            {
                var product = BuildProductDTO(vm);

                var createResult = await _productService.CreateProduct(product);

                if (createResult)
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }

            vm.ColorList = _productService.GetProductColors().Select(o => new ColorOptionVM(o)).ToList();
            vm.Error     = true; // since we made it here, flag the error and return to create page

            return(View("Save", vm));
        }
Exemplo n.º 9
0
        public IActionResult Save(ProductSaveVM product)
        {
            var products = _productService.AddProduct(product);

            return(View(products));
        }