Ejemplo n.º 1
0
        public byte[] GetDispatchPDF(int dispatchId, bool ifSendEmail = false)
        {
            if (UserHelper.IsAuthorize(new List <int> {
                (int)UserType.SuperAdmin, (int)UserType.Admin, (int)UserType.Client
            }))
            {
                try
                {
                    DispatchDetailsPDF dispatchInfoToPDF = _dispatchManager.GetDispatchDetails(dispatchId);
                    Dispatch           dispatch          = _context.Dispatches.FirstOrDefault(d => d.Id == dispatchId && d.Deleted_At == null);
                    User   userCreator = _context.Users.FirstOrDefault(u => u.Id == dispatch.Creator_Id && u.Deleted_at == null);
                    string creatorName = "";
                    if (userCreator != null)
                    {
                        creatorName = userCreator.Login;//zmienic na imie i nazwisko
                    }

                    byte[] result = _pdfManager.GenerateDispatchPDF(dispatchInfoToPDF, creatorName);
                    if (ifSendEmail)
                    {
                        _pdfManager.SendEmail("Dispatch_" + dispatch.Dispatch_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"));
            }
        }