Exemplo n.º 1
0
        public IActionResult Accept(int?id)
        {
            if (id == null)
            {
                TempData["Msg"]     = "Something went wrong, try again later!";
                TempData["Styling"] = "alert rounded shadow alert-danger";
                return(RedirectToAction("index"));
            }
            var returnn       = _context.Returns.Include(o => o.Customer).FirstOrDefault(o => o.Id == id);
            var returnDetails = _context.ReturnDetails.Include(o => o.Product).FirstOrDefault(o => o.ReturnId == id);
            var customer      = _context.Customers.FirstOrDefault(o => o.Id == returnn.CustomerId);
            var product       = _context.Products.FirstOrDefault(o => o.Id == returnDetails.ProductId);
            var orderDetail   = _context.OrderDetails.FirstOrDefault(o => o.ProductId == product.Id && o.OrderId == returnn.OrderId);

            if (returnn == null || returnDetails == null || customer == null || product == null || orderDetail == null || returnn.ReturnStatusId != 1)
            {
                TempData["Msg"]     = "Something went wrong, try again later!";
                TempData["Styling"] = "alert rounded shadow alert-danger";
                return(RedirectToAction("index"));
            }
            customer.Credit       += returnn.TotalPrice;
            returnn.ReturnStatusId = 2;
            DateTime now     = DateTime.Now;
            DateTime expDate = (DateTime)orderDetail.ExpDate;

            if ((expDate - now).Days > 30)
            {
                product.Quantity += returnDetails.Quantity;
                try
                {
                    _context.Update(product);
                    _context.SaveChanges();
                }
                catch
                {
                    TempData["Msg"]     = "Something went wrong, try again later!";
                    TempData["Styling"] = "alert rounded shadow alert-danger";
                    return(RedirectToAction("index"));
                }
            }
            try
            {
                _context.Update(customer);
                _context.Update(returnn);
                _context.SaveChanges();
            }
            catch
            {
                TempData["Msg"]     = "Something went wrong, try again later!";
                TempData["Styling"] = "alert rounded shadow alert-danger";
                return(RedirectToAction("index"));
            }

            TempData["Msg"]     = "Return " + returnn.Id + " was accepted";
            TempData["Styling"] = "alert rounded shadow alert-success";
            return(RedirectToAction("index"));
        }
Exemplo n.º 2
0
        public IActionResult Return(int?OrderId, int?ProductId, int?Quantity, string?Reason)
        {
            if (OrderId == null || ProductId == null)
            {
                return(NotFound());
            }
            Orders       order   = _context.Orders.FirstOrDefault(m => m.Id == OrderId);
            OrderDetails details = _context.OrderDetails.Where(m => m.OrderId == OrderId).Include(o => o.Product).FirstOrDefault(o => o.ProductId == ProductId);

            if (Quantity == 0 || Quantity == null || Reason == null || Quantity > details.Quantity)
            {
                TempData["DangerMsg"] = "Quantity must be greater than 0 but lower then total ordered quantity and reason is required";
                TempData["Styling"]   = "alert rounded shadow alert-danger";
                return(RedirectToAction("Details", new { id = OrderId }));
            }

            Returns returnn = new Returns
            {
                CustomerId     = (int)order.CustomerId,
                OrderId        = order.Id,
                ReturnStatusId = 1,
                TotalPrice     = 0
            };

            _context.Add(returnn);
            _context.SaveChanges();
            ReturnDetails returnDetails = new ReturnDetails
            {
                ReturnId  = returnn.Id,
                ProductId = (int)ProductId,
                Quantity  = (int)Quantity,
                Reason    = (string)Reason
            };

            returnn.TotalPrice = details.Price * returnDetails.Quantity;
            try
            {
                _context.Update(returnn);
                _context.Add(returnDetails);
                _context.SaveChanges();
                TempData["SuccessMsg"] = "Return request was sent";
                TempData["Styling"]    = "alert rounded shadow alert-success";
            }
            catch {
                TempData["DangerMsg"] = "Something went wrong, try again later!";
                TempData["Styling"]   = "alert rounded shadow alert-danger";
                return(RedirectToAction("Details", new { id = OrderId }));
            }



            return(RedirectToAction("Details", new { id = OrderId }));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> AcceptOrder(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var order = await _context.Orders.Include(o => o.OrderStatus).FirstOrDefaultAsync(o => o.Id == id);

            if (order.OrderStatus.Status != "Sent")
            {
                return(NotFound());
            }
            order.OrderStatusId = 9;
            var employee = await GetEmployeeByUserIdAsync();

            order.EmployeeId = employee.Id;
            try
            {
                TempData["successMsg"] = "Order " + order.Id.ToString() + " was accepted";
                _context.Update(order);
                _context.SaveChanges();
            }
            catch
            {
                return(NotFound());
            }

            //TempData["Warning"] = "";
            //TempData["danger"] = "alert rounded shadow alert-danger";


            TempData["success"] = "alert rounded shadow alert-success";
            return(RedirectToAction("index"));
        }