Example #1
0
        public byte[] GetDifferenceDeliveryPDF([FromBody] Committee commitee, int orderId, bool ifSendEmail = false)
        {
            if (UserHelper.IsAuthorize(new List <int> {
                (int)UserType.SuperAdmin, (int)UserType.Admin
            }))
            {
                try
                {
                    Delivery deliveryToPdf = _context.Deliveries.FirstOrDefault(d => d.Order_Id == orderId && d.Deleted_At == null);
                    if (deliveryToPdf != null && !(bool)deliveryToPdf.If_Differential_Delivery_Order)
                    {
                        throw new Exception("This delivery is the same like order");
                    }
                    else
                    {
                        Order orderToPdf = _context.Orders.FirstOrDefault(o => o.Id == deliveryToPdf.Order_Id && o.Deleted_At == null);
                        List <Orders_Positions> orderPositionsToPdf = _context.Orders_Positions.Where(o => o.Order_id == deliveryToPdf.Order_Id && o.Deleted_At == null).ToList();
                        User   userCreator = _context.Users.FirstOrDefault(u => u.Id == deliveryToPdf.Creator_Id && u.Deleted_at == null);
                        string creatorName = "";
                        if (userCreator != null)
                        {
                            creatorName = userCreator.Login;//Do zmiany na imie i nazwisko
                        }
                        byte[] result = _pdfManager.GenerateDifferenceDeliveryPDF(deliveryToPdf, orderToPdf, orderPositionsToPdf, commitee);
                        if (ifSendEmail)
                        {
                            _pdfManager.SendEmail("Difference_" + deliveryToPdf.Delivery_Number, result);
                        }
                        // Zmienić creatora na creatora delivery czyli przyjmujacego zamowienie - trzeb dodać w bazie
                        return(result);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.ToString());
                }
            }

            else
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "User don't have acces to this method"));
            }
        }