Exemplo n.º 1
0
 // NOTE : Pattern used when using SonarQube or any other code analysis tools
 private void AssureProductIsNotNull(ViewModels.Product product)
 {
     if (product == null)
     {
         throw new ArgumentNullException(nameof(product));
     }
 }
Exemplo n.º 2
0
        public IActionResult AddProduct([FromForm] ViewModels.Product product)
        {
            var user  = User.Claims.Where(u => u.Type == ClaimTypes.UserData).FirstOrDefault().Value;
            var owner = new Guid(user);

            _productService.Create(product, owner);
            return(Ok());
        }
Exemplo n.º 3
0
        public static ViewModels.Product MapToViewModel(Product model)
        {
            var product = new ViewModels.Product
            {
                Id      = model.Id,
                Brand   = model.Brand,
                InStock = model.InStock,
                Model   = model.Model,
                Price   = model.Price
            };

            return(product);
        }
Exemplo n.º 4
0
        public static Product MapToModel(ViewModels.Product vm)
        {
            var product = new Product
            {
                Id      = vm.Id,
                Brand   = vm.Brand,
                InStock = vm.InStock,
                Model   = vm.Model,
                Price   = vm.Price
            };

            return(product);
        }
Exemplo n.º 5
0
        public void Edit(ViewModels.Product editProduct)
        {
            var product = _unitOfWork.ProductRepository.FirstOrDefault(p => p.ProductId == editProduct.ProductId);

            product.Title       = editProduct.Title;
            product.Status      = (Enums.Product.ProductStatus)editProduct.StatusValue == Enums.Product.ProductStatus.Enable ? Enums.Product.ProductStatus.PendingApproval : (Enums.Product.ProductStatus)editProduct.StatusValue;
            product.Description = editProduct.Description;
            product.Price       = editProduct.Price;
            if (editProduct.CarModelId != null || editProduct.CarModelId != Guid.Empty)
            {
                product.CarModelId = editProduct.CarModelId;
            }

            _unitOfWork.ProductRepository.Edit(product);
            _unitOfWork.Commit();
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Add(ViewModels.Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var mapped = new Mapper(new MapperConfiguration(cfg => cfg.CreateMap <ViewModels.Product, Product>()
                                                            .ForMember("Slug", opt => opt.MapFrom(src => src.Name.GenerateSlug("-")))
                                                            ));

            var entity = mapped.Map <Product>(product);

            await Repository.Add(entity);

            return(Ok());
        }
Exemplo n.º 7
0
        public void Create(ViewModels.Product newProduct, Guid ownerId)
        {
            var product = new Classics.Data.Models.Product();

            product.ProductId   = Guid.NewGuid();
            product.Title       = newProduct.Title;
            product.Status      = Enums.Product.ProductStatus.PendingApproval;
            product.Description = newProduct.Description;
            product.Price       = newProduct.Price;
            product.CreatedOn   = DateTime.Now;
            product.OwnerId     = ownerId;
            if (newProduct.CarModelId != null || newProduct.CarModelId != Guid.Empty)
            {
                product.CarModelId = newProduct.CarModelId;
            }

            _unitOfWork.ProductRepository.Add(product);
            _unitOfWork.Commit();
        }
Exemplo n.º 8
0
        public static IEnumerable <ViewModels.Product> MapToViewModel(IEnumerable <Product> models)
        {
            var products = new List <ViewModels.Product>();

            foreach (var model in models)
            {
                var product = new ViewModels.Product
                {
                    Id      = model.Id,
                    Brand   = model.Brand,
                    InStock = model.InStock,
                    Model   = model.Model,
                    Price   = model.Price
                };

                products.Add(product);
            }

            return(products);
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Edit(ViewModels.Product product)
        {
            var entity = await Repository.GetById(product.Id);

            if (entity == null)
            {
                ModelState.AddModelError("Id", "The record id is missing or was entered incorrectly.");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            new Mapper(new MapperConfiguration(cfg => cfg.CreateMap <ViewModels.Product, Product>()
                                               .ForMember("Slug", opt => opt.MapFrom(src => src.Name.GenerateSlug("-")))
                                               )).Map(product, entity);

            await Repository.Edit(entity);

            return(Ok());
        }
Exemplo n.º 10
0
 public AddToCart()
 {
     Product    = new ViewModels.Product();
     CreateTime = DateTime.Now;
 }
Exemplo n.º 11
0
 public IActionResult EditProduct([FromForm] ViewModels.Product product)
 {
     _productService.Edit(product);
     return(Ok());
 }