Esempio n. 1
0
        public IActionResult PutOrderAccept([FromBody] OrderViewModel orderVmdl)
        {
            try
            {
                var order      = _bl.GetOrders(orderVmdl.OrderId);
                var orderItems = order.OrderItems.ToList();
                var changed    = orderVmdl.OrderItems
                                 .Where(i => i.IsDeclined)
                                 .Select(i => i.ItemId)
                                 .ToList();

                orderItems
                .Where(i => changed.Contains(i.ItemId))
                .ToList()
                .ForEach(i => i.IsDeclined = true);


                orderVmdl.Accept(order, _bl);
                _bl.SaveChanges();
                orderVmdl.LoadOrderItems(order).Refresh(order);

                ////////////////Mail Part
                Task task = new Task(() => SendMail(orderVmdl));
                task.Start();

                return(Ok(orderVmdl));
            }
            catch (SecurityException)
            {
                _log.LogWarning("Security: '{0}' tried to update Order '{1}'", _bl.GetCurrentUid(), orderVmdl.OrderId);
                return(Unauthorized());
            }

            catch (Exception ex)
            {
                _log.LogError("Exception: '{0}'", ex);
                return(StatusCode(500));
            }
        }