public async Task <ActionResult> CreateReview([FromBody] Review dto)
        {
            try
            {
                await _context.Reviews.AddAsync(dto);

                await _context.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Example #2
0
        public async Task <ActionResult> SetResellPrice(Guid prodID, [FromBody] decimal price)
        {
            var userRole = User.Claims.FirstOrDefault(x => x.Type == "role")?.Value;

            var product = await _context.Products.FindAsync(prodID);

            if (product == null)
            {
                return(NotFound());
            }

            try
            {
                ResellHistory newModel = new ResellHistory()
                {
                    Id        = new Guid(),
                    productId = prodID,
                    oldPrice  = product.Price,
                    newPrice  = price,
                    created   = DateTime.Now
                };

                product.Price = price;
                _context.Products.Update(product);
                await _context.SaveChangesAsync();

                _context.ResellHistory.Add(newModel);
                await _context.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }