Ejemplo n.º 1
0
        public byte[] GetOrderPDF(int orderId, bool ifSendEmail = false)
        {
            if (UserHelper.IsAuthorize(new List <int> {
                (int)UserType.SuperAdmin, (int)UserType.Admin, (int)UserType.Client
            }))
            {
                try
                {
                    Order orderToPdf = _context.Orders.FirstOrDefault(o => o.Id == orderId && o.Deleted_At == null);
                    List <Orders_Positions> orderPositionsToPdf = _context.Orders_Positions.Where(o => o.Id == orderId && o.Deleted_At == null).ToList();
                    User   userCreator = _context.Users.FirstOrDefault(u => u.Id == orderToPdf.Creator_Id && u.Deleted_at == null);
                    string creatorName = "";
                    if (userCreator != null)
                    {
                        creatorName = userCreator.Name + " " + userCreator.Surname;//zmienic na imie i nazwisko
                    }
                    byte[] result = _pdfManager.GenerateOrderPDF(orderToPdf, orderPositionsToPdf, creatorName);
                    if (ifSendEmail)
                    {
                        _pdfManager.SendEmail("Order_" + orderToPdf.Order_Number, result);
                    }
                    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"));
            }
        }