Example #1
0
        public ActionResult <Product> EditProduct(NewProductRequest p)
        {
            Product prod = new Product(p);

            Console.WriteLine(prod.Id);
            return(_ps.UpdateProduct(prod));
        }
Example #2
0
        //[ApiExplorerSettings(IgnoreApi = true)]
        public async Task <ActionResult <ReturnObject> > NewProduct([FromBody] NewProductRequest newproduct)
        {
            DNewProductRequest ndf = new DNewProductRequest();

            _mapper.Map(newproduct, ndf);
            return(_mapper.Map <ReturnObject>(await _mediator.Send(new NewProduct(ndf))));
        }
Example #3
0
 public Product(NewProductRequest req)
 {
     if (req.Id != null)
     {
         Id = req.Id;
     }
     Name  = req.Name;
     Price = req.Price;
     if (!req.DiscountAmount.Equals(0))
     {
         IDiscount disc;
         if (req.DiscountIsAbsolute)
         {
             disc = new AbsoluteDiscount();
         }
         else
         {
             disc = new PercentageDiscount();
         }
         disc.Amount = req.DiscountAmount;
         disc.Reason = req.Reason;
         Discount    = disc;
         calculatePrice();
     }
 }
Example #4
0
        public ActionResult <Product> CreateProduct(NewProductRequest npr)
        {
            Product product = new Product(npr);

            _ps.AddProduct(product);
            return(Ok(JsonSerializer.Serialize(product)));
        }
        public async Task <RegisteredProduct> Handle(NewProductRequest request, CancellationToken cancellationToken)
        {
            var product = request.ToEntity();

            this._dbContext.Products.Add(product);
            await this._dbContext.SaveChangesAsync();

            return(product.ToDTO());
        }
        public IActionResult InsertNewNotification(Guid userId, [FromBody] NewProductRequest incomingProduct) // [FromBody] tag is a must to clarify
        {
            var productId = Guid.NewGuid();

            if (incomingProduct.newProduct)
            {
                if (_context.Products.Where(x => x.ProductName == incomingProduct.ProductName && x.UserId == userId).FirstOrDefault() == null)
                {
                    var newProduct = new Product();
                    newProduct.ProductId   = productId;
                    newProduct.Barcode     = incomingProduct.Barcode;
                    newProduct.Category    = incomingProduct.Category;
                    newProduct.ProductName = incomingProduct.ProductName;
                    newProduct.UserId      = userId;

                    _context.Products.Add(newProduct);
                }
                else
                {
                    productId = _context.Products.Where(x => x.ProductName == incomingProduct.ProductName).First().ProductId;
                }
            }
            else if (incomingProduct.productId != null)
            {
                productId = incomingProduct.productId.Value;

                Product product = _context.Products.FirstOrDefault(x => x.ProductId == productId && x.UserId == userId);
                if (incomingProduct.ProductName != "" && incomingProduct.ProductName != product.ProductName)
                {
                    product.ProductName = incomingProduct.ProductName;
                }
                if (incomingProduct.Category != "" && incomingProduct.Category != product.Category)
                {
                    product.Category = incomingProduct.Category;
                }

                _context.Products.Update(product);
            }
            else
            {
                productId = _context.Products.Where(x => x.ProductName == incomingProduct.ProductName).First().ProductId;
            }

            Notification notifcation = new Notification();

            notifcation.NotificationId = new Guid();
            notifcation.ProductId      = productId;
            notifcation.UserId         = userId;
            notifcation.EntryDate      = DateTime.Now;
            notifcation.ExpiryDate     = DateTime.Now.AddDays(incomingProduct.ReservedDays);
            notifcation.IsEaten        = false;
            notifcation.Note           = incomingProduct.Note;
            _context.Notifications.Add(notifcation);
            _context.SaveChanges();

            return(Ok());
        }
        public async Task <IActionResult> Post([FromBody] NewProductRequest request)
        {
            var product = Product.Create(request.SKU, request.DisplayName, request.UnitPrice, request.Description);

            _repository.Add(product);

            await _repository.UnitOfWork.SaveChangesAsync();

            return(Ok(product));
        }
 public static Product ToEntity(this NewProductRequest request)
 {
     return(new Product
     {
         AditionalDrescription = request.AditionalDrescription,
         Brand = request.Brand,
         Model = request.Model,
         Name = request.Name,
         TechnicalDescription = request.TechnicalDescription,
         Price = request.Price
     });
 }
Example #9
0
        public async Task <IActionResult> update(NewProductRequest request, int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var(state, response) = await _productServices.update(request, id);

            if (state == true)
            {
                return(Ok(response));
            }

            return(BadRequest(response));
        }
Example #10
0
        public async Task <(bool state, object response)> update(NewProductRequest request, int id)
        {
            var product = await _context.Products.Include(p => p.Category).SingleOrDefaultAsync(p => p.Id == id);

            if (product == null)
            {
                return(false, new { message = "Product Not Found or Does not exists" });
            }

            product.Name        = request.Name;
            product.Description = request.Description;
            product.Price       = request.Price;
            product.CategoryId  = request.CategoryId;

            await _context.SaveChangesAsync();

            return(true, transform(product));
        }
Example #11
0
        public async Task <(bool state, object response)> store(NewProductRequest request)
        {
            var category = await _context.Category.FindAsync(request.CategoryId);

            if (category == null)
            {
                return(false, new { message = "Selected Category does not exists" });
            }

            var product = new Product {
                Name        = request.Name,
                Description = request.Description,
                Price       = request.Price,
                CategoryId  = request.CategoryId,
                CreatedAt   = DateTimeOffset.Now
            };

            await _context.AddAsync(product);

            await _context.SaveChangesAsync();


            return(true, transform(product));
        }
 public async Task <RegisteredProduct> AddNewClient([FromBody] NewProductRequest request)
 {
     return(await _mediator.Send(request));
 }