public PartialViewResult OpenProduct(Guid? idProduct = null)
        {
            var productModel = new ProductModel();

            if (idProduct.HasValue)
            {
                productModel = ProductBL.GetProductById(idProduct.Value);
            }

            return PartialView("ProductPartial", productModel);
        }
        public static int ConvertHtmlSringBdsDossierToPdf(ProductModel product, string destinationPath, Guid idUser, FirmInstitutionViewModel firmCGP, Guid? idDocument, bool forceDownload, string logoUrl = "")
        {
            int pageCount = 0;
            Byte[] documentBytes = null;
            try
            {

                DocumentModel documentModel = GetDocumentModelFromId(product.IdDocumentModel.GetValueOrDefault());
                if (documentModel != null && idDocument.HasValue)
                {
                    string strHtmlMapped = null;
                    string strFooter = null;


                    var model = EntityToModel(documentModel);
                    strHtmlMapped = AppendIntoBodyHtml(model.HtmlTemplate);

                    ExpertPDFHelper expertPdfEngine = new ExpertPDFHelper();
                    documentBytes = expertPdfEngine.GeneratePdfBytesUsingComponent(ParserHtmlMethod(documentModel, idDocument.Value, strHtmlMapped, logoUrl, false, firmCGP), product.Name, strFooter, false);

                    FoxitPDFGenerator pdfGen = new FoxitPDFGenerator();

                    //FirmInstitution firm = firmInstitutionSDG;
                    //string logoPathFileName = Utility.FileManager.BuildLogoPath(firm.idFirmInstitution) + firm.Logo;
                    string docTitle = string.Empty; //TODO : multilingue
                    string ownerName = product.Name;

                    pdfGen.GenerateMergeByteDocument(documentModel.IdDocumentModel, documentBytes, destinationPath, "", forceDownload, out pageCount, Upsilab.Business.Document.ElectronicSafeDocumentBL.DocumentType.SF.ToString(), "center", docTitle, ownerName,false,false);

                }
            }
            catch (Exception ex)
            {
                Log.Log.AppendException(new Exception(string.Format("Erreur lors de la génération du template HTML en PDF : {0}", ex.Message)));
            }

            return pageCount;
        }
        //Prepare list of product Document
        private List<DocumentVM> GetProductDocument(ProductModel productModel)
        {
            string descriptionSf = "1 exemplaire à renvoyer signé à NextStage AM 19 Avenue George V 75008 Paris et 1 exemplaire à remettre au client";
            return  new List<DocumentVM>()
	        { //TODO : multilingue
                new DocumentVM() { DocumentTypeCode = ElectronicSafeDocumentBL.DocumentType.SF.ToString(), UrlDocument = "BulletinDeSouscription.pdf", Label = "Bulletin de souscription",Description=descriptionSf, IdProduct = productModel.IdProduct  },
                new DocumentVM() { DocumentTypeCode = ElectronicSafeDocumentBL.DocumentType.DICI.ToString(), UrlDocument = productModel.DICIFilename, Label = productModel.DICILabel,Description = "A remettre aux clients", IdProduct = productModel.IdProduct  },
                new DocumentVM() { DocumentTypeCode = ElectronicSafeDocumentBL.DocumentType.BROC.ToString(), UrlDocument = productModel.BrochureFilename, Label = productModel.BrochureLabel,Description = "A remettre aux clients", IdProduct = productModel.IdProduct },
	        };
        }
        public ActionResult SaveProduct(ProductModel productModel, IEnumerable<HttpPostedFileBase> files)
        {
            try
            {
                var firmInstituionSDG = SessionManager.GetFirmInstitutionSession();

                var brochureFile = Request.Files["brochureFile"];
                var diciFile = Request.Files["diciFile"];

                var brochureLabel = Request.Form["brochureLabel"];
                var diciLabel = Request.Form["diciLabel"];

                //Check if pdf file
                if (brochureFile != null && brochureFile.ContentLength > 0 && !FileManager.IsPDF(brochureFile.FileName)
                    || diciFile != null && diciFile.ContentLength > 0 && !FileManager.IsPDF(diciFile.FileName))
                {
                    throw new Exception("Merci de télécharger des fichiers pdf.");
                }

                //Save brochure file
                if (brochureFile != null && brochureFile.ContentLength > 0 && FileManager.IsPDF(brochureFile.FileName))
                {
                    var docType = ElectronicSafeDocumentBL.DocumentType.BROC.ToString();
                    var fullPath = ElectronicSafeDocumentBL.BuildProviderDocumentPath(firmInstituionSDG.FirmInstitutionName, firmInstituionSDG.idFirmInstitution, docType.ToDocumentTypeEnum(), true);
                    var brochureFileName = ElectronicSafeDocumentBL.BuildDocumentName(docType, productModel.IdProduct);
                    string filePath = System.IO.Path.Combine(fullPath, brochureFileName);

                    brochureFile.SaveAs(filePath);

                    productModel.BrochureFilename = brochureFileName;                    
                }

                //Save DICI file
                if (diciFile != null && diciFile.ContentLength > 0 && FileManager.IsPDF(diciFile.FileName))
                {
                    var docType = ElectronicSafeDocumentBL.DocumentType.DICI.ToString();
                    var fullPath = ElectronicSafeDocumentBL.BuildProviderDocumentPath(firmInstituionSDG.FirmInstitutionName, firmInstituionSDG.idFirmInstitution, docType.ToDocumentTypeEnum(), true);
                    var diciFileFileName = ElectronicSafeDocumentBL.BuildDocumentName(docType, productModel.IdProduct);
                    string filePath = System.IO.Path.Combine(fullPath, diciFileFileName);

                    diciFile.SaveAs(filePath);

                    productModel.DICIFilename = diciFileFileName;                   
                }

                productModel.IdFirmInstitution = firmInstituionSDG.idFirmInstitution;
                productModel.BrochureLabel = brochureLabel;
                productModel.DICILabel = diciLabel;

                //Save to database
                //Add
                if (productModel.IdProduct == Guid.Empty)
                {
                    productModel.IdProduct = Guid.NewGuid();
                  
                    var newProduct = productModel.ToEntity();
                    

                    ProductBL.AddProduct(newProduct);
                }
                else //update
                {
                    ProductBL.UpdateProduct(productModel);
                }
            }
            catch (Exception ex)
            {
                Upsilab.Business.Log.Log.AppendException(ex);
            }

            return RedirectToAction("Index");
        }
        public string UpdateDatesObligationReglementairesOld(string id, string derQuest, string proQuest, string derEtu, string proEtu)
        {
            try
            {
                Guid idProduct = Guid.Empty;
                Guid.TryParse(id, out idProduct);
                ProductModel productModel = new ProductModel();
                productModel = ProductBL.GetProductObligationById(idProduct);
                productModel.DateObligationObjetList.Clear();
                if (!string.IsNullOrEmpty(derQuest))
                {
                    productModel.DateObligationObjetList.Add(new DateObligationObjetVm() { DateObligation = DateTime.ParseExact(derQuest, "dd/MM/yyyy", CultureInfo.InvariantCulture)});
                }
                else
                {
                    productModel.DateObligationObjetList.Add(new DateObligationObjetVm() { DateObligation = null });                   
                }

                if (!string.IsNullOrEmpty(proQuest))
                {
                    productModel.DateObligationObjetList.Add(new DateObligationObjetVm()
                    {
                        DateObligation = DateTime.ParseExact(proQuest, "dd/MM/yyyy", CultureInfo.InvariantCulture)
                    });
                }
                else
                {
                    productModel.DateObligationObjetList.Add(new DateObligationObjetVm() { DateObligation = null }); 
                }

                if (!string.IsNullOrEmpty(derEtu))
                {
                    productModel.DateObligationObjetList.Add(new DateObligationObjetVm() { DateObligation = DateTime.ParseExact(derEtu, "dd/MM/yyyy", CultureInfo.InvariantCulture)});
                }
                else
                {
                    productModel.DateObligationObjetList.Add(new DateObligationObjetVm() { DateObligation = null }); 
                }

                if (!string.IsNullOrEmpty(proEtu))
                {
                    productModel.DateObligationObjetList.Add(new DateObligationObjetVm() { DateObligation =  DateTime.ParseExact(proEtu, "dd/MM/yyyy", CultureInfo.InvariantCulture)});
                }
                else
                {
                    productModel.DateObligationObjetList.Add(new DateObligationObjetVm() { DateObligation = null }); 
                }
                ProductBL.UpdateProduct(productModel);
                return "ok";
            }
            catch (Exception ex)
            {
                Upsilab.Business.Log.Log.AppendException(ex);
                return "ko";
            }

        }
Exemplo n.º 6
0
        public static IEnumerable<SubscriptionFileViewModel> GetInformationSubscriptionFilesCgp(Guid idUser, string letter = "tous", string search = "")
        {
            using (var ctx = new UpsilabEntities())
            {
                letter = letter.ToLower();
                search = search.ToLower();

                var SFCrit = Upsilab.Business.Document.ElectronicSafeDocumentBL.DocumentType.SF.ToString();
                var entity = (from sf in ctx.SubscriptionFile
                    from p in ctx.Product.Where(x => sf.IdProduct == x.IdProduct)
                    from fr in ctx.FirmInstitution.Where(x => x.idFirmInstitution == p.IdFirmInstitution)
                    from sg in ctx.SignatureTransaction.Where(x => sf.IdSignatureTransaction == x.idSignatureTransaction)
                    from ci in ctx.CustomerProspect.Where(x => x.idCustomer == sf.IdCustomerProspect1).DefaultIfEmpty()
                    from dc in ctx.Document.Where(x => x.idSignatureTransaction == sg.idSignatureTransaction)
                    from fv in ctx.FieldValue.Where(x => x.IdDocument == dc.idDocument).DefaultIfEmpty()
                    from fd in ctx.Fields.Where(x => x.IdField == fv.IdField).DefaultIfEmpty()
                    where (sf.IdUserCreated == idUser && dc.DocumentType == SFCrit && !sf.IsDeleted)
                    select new { sf,p,sg,fr,ci,dc,fv,fd} 
                ).ToList();

                List<SubscriptionFileModel> list = new List<SubscriptionFileModel>();
                if (entity != null)
                {
                    List<SubscriptionFileModel> sfLst = new List<SubscriptionFileModel>();
                    entity.ForEach(itm =>
                    {
                        if (!sfLst.Any(x => x.IdSubscriptionFile == itm.sf.IdSubscriptionFile))
                        {
                            var model = new SubscriptionFileModel();
                            model.Role = FrsRole.CGP;
                            model.IdSubscriptionFile = itm.sf.IdSubscriptionFile;
                            model.DateCreated = itm.sf.DateCreated;
                            model.SubmissionMode = itm.sf.SubmissionMode;
                            model.DatesReportsLab = itm.sf.DatesReportLab;
                            var st = new SignatureTransactionEntity();
                            st.IdSignatureTransaction = itm.sg.idSignatureTransaction;
                            st.Status = itm.sg.Status;
                            st.DateSignaturesObjet = itm.sg.DateSignaturesObjet;
                            model.SignatureTransaction = st;
                            var pt = new ProductModel();
                            pt.IdProduct = itm.p.IdProduct;
                            pt.Name = itm.p.Name;
                            var frm = new FirmInstitutionViewModel();
                            frm.IdFirmInstitution = itm.fr.idFirmInstitution;
                            frm.Email = itm.fr.E_mail;
                            frm.FirmInstitutionName = itm.fr.FirmInstitutionName;
                            pt.FirmInstitution = frm;
                            model.Product = pt;

                            var ui = new UserModel();
                            if (itm.fv != null && itm.fv.Fields != null)
                            {
                                ui.UserName = itm.fv.Fields.NameKey == NOM_SSC ? itm.fv.Value : string.Empty;
                                ui.UserFirstName = itm.fv.Fields.NameKey == PRENOM_SSC ? itm.fv.Value : string.Empty;
                                ui.UserMobilePhone = itm.fv.Fields.NameKey == MOBILE_SSC ? itm.fv.Value : string.Empty;
                                ui.IdDocument = itm.fv.IdDocument;
                            }
                            model.User = ui;
                            
                            sfLst.Add(model);
                        }
                        else
                        {
                            var item = sfLst.FirstOrDefault(x => x.IdSubscriptionFile == itm.sf.IdSubscriptionFile);
                            if (item != null)
                            {
                                if (item.User != null && itm.dc != null && item.User.IdDocument == itm.dc.idDocument)
                                {
                                    if (string.IsNullOrEmpty(item.User.UserName) && itm.fv.Fields.NameKey == NOM_SSC)
                                        item.User.UserName = itm.fv.Value;
                                    if (string.IsNullOrEmpty(item.User.UserFirstName) && itm.fv.Fields.NameKey == PRENOM_SSC)
                                        item.User.UserFirstName = itm.fv.Value;
                                    if (string.IsNullOrEmpty(item.User.UserMobilePhone) && itm.fv.Fields.NameKey == MOBILE_SSC)
                                        item.User.UserMobilePhone = itm.fv.Value;
                                }
                            }
                        }

                    });

                    #region "FILTER"

                    list = sfLst.ToList();

                    list.ForEach(delegate(SubscriptionFileModel sf)
                    {
                        sf.UserCgp = GetUserModelBySubscriptionFile(sf.IdSubscriptionFile);
                    });

                    if (!string.IsNullOrEmpty(letter) && letter.ToUpper() != "TOUS")
                    {
                        list =
                            list.Where(
                                x =>
                                    (x.User != null && x.User.UserName != null && x.User.UserFirstName != null &&
                                     (x.User.UserName.ToLower().StartsWith(letter) || x.User.UserFirstName.ToLower().StartsWith(letter))) ||
                                    (x.FirmInstitution != null && x.FirmInstitution.FirmInstitutionName.ToLower().StartsWith(letter))).ToList();
                    }
                    else if (!string.IsNullOrEmpty(search))
                    {
                        list = list.Where(x =>
                 (x.User != null && x.User.UserName != null && x.User.UserFirstName != null &&
                  (x.User.UserName.ToLower().Contains(search) || x.User.UserFirstName.ToLower().Contains(search))) ||
                 (x.FirmInstitution != null && x.FirmInstitution.FirmInstitutionName.ToLower().Contains(search))).ToList();
                    }
                    #endregion
                }
                

                return list.ToList().ToViewModel();
            }
        }
Exemplo n.º 7
0
        public static IEnumerable<SubscriptionFileViewModel> GetInformationSubscriptionFilesFrs(Guid idFirmInstitution, string letter = "tous", string search = "")
        {
            using (var ctx = new UpsilabEntities())
            {
                letter = letter.ToLower();
                search = search.ToLower();

                var SFCrit = Upsilab.Business.Document.ElectronicSafeDocumentBL.DocumentType.SF.ToString();
                var entity = (from sf in ctx.SubscriptionFile
                              from p in ctx.Product.Where(x => sf.IdProduct == x.IdProduct)
                              from cgp in ctx.User.Where(x => x.idUser == sf.IdUserCreated)
                              from sg in ctx.SignatureTransaction.Where(x => sf.IdSignatureTransaction == x.idSignatureTransaction)
                              from firm in ctx.FirmInstitution.Where(x => x.idFirmInstitution == p.IdFirmInstitution)
                              from ci in ctx.CustomerProspect.Where(x => x.idCustomer == sf.IdCustomerProspect1).DefaultIfEmpty()
                              from dc in ctx.Document.Where(x => x.idSignatureTransaction == sg.idSignatureTransaction)
                              from fv in ctx.FieldValue.Where(x => x.IdDocument == dc.idDocument).DefaultIfEmpty()
                              from fd in ctx.Fields.Where(x => x.IdField == fv.IdField).DefaultIfEmpty()
                              where (firm.idFirmInstitution == idFirmInstitution && dc.DocumentType == SFCrit && !sf.IsDeleted)
                              select new { sf,p,cgp,sg,firm,ci,dc,fv,fd}
            ).ToList();

                List<SubscriptionFileModel> list = new List<SubscriptionFileModel>();
                if (entity != null)
                {
                    List<SubscriptionFileModel> sfLst = new List<SubscriptionFileModel>();
                    var lst = new List<SubscriptionFileModel>();
                    entity.ForEach(x => {
                        var model = new SubscriptionFileModel();
                        model.Role = FrsRole.FRS;
                        model.IdSubscriptionFile = x.sf.IdSubscriptionFile;
                        model.DateCreated = x.sf.DateCreated;
                        model.SubmissionMode = x.sf.SubmissionMode;
                        model.DatesReportsLab = x.sf.DatesReportLab;
                        model.EmailUserCreator = x.cgp.UserEmail;

                        var signature = new SignatureTransactionEntity();
                        signature.IdSignatureTransaction = x.sg.idSignatureTransaction;
                        signature.Status = x.sg.Status;
                        signature.DateSignaturesObjet = x.sg.DateSignaturesObjet;
                        model.SignatureTransaction = signature;

                        var product = new ProductModel();
                        product.IdProduct = x.p.IdProduct;
                        product.Name = x.p.Name;
                        model.Product = product;

                        var user = new UserModel();
                        user.UserName = x.fv != null && x.fv.Fields != null && !string.IsNullOrEmpty(x.fv.Fields.NameKey) && x.fv.Fields.NameKey == NOM_SSC ? x.fv.Value : string.Empty;
                        user.UserFirstName = x.fv != null && x.fv.Fields != null && !string.IsNullOrEmpty(x.fv.Fields.NameKey) && x.fv.Fields.NameKey == PRENOM_SSC ? x.fv.Value : string.Empty;
                        user.UserMobilePhone = x.fv != null && x.fv.Fields != null && !string.IsNullOrEmpty(x.fv.Fields.NameKey) && x.fv.Fields.NameKey == MOBILE_SSC ? x.fv.Value : string.Empty;
                        user.IdDocument = x.fv != null ? x.fv.IdDocument : Guid.Empty;
                        model.User = user;

                        var firmInstitution = new FirmInstitutionViewModel();
                        firmInstitution.IdFirmInstitution = x.firm.idFirmInstitution;
                        firmInstitution.Email = x.firm.E_mail;
                        firmInstitution.FirmInstitutionName = x.firm.FirmInstitutionName;
                        model.FirmInstitution = firmInstitution;

                        if (x.ci != null)
                        {
                            var customerProspect = new CustomerProspectViewModel();
                            customerProspect.DateUpdatedLast = x.ci.DateUpdatedLast;
                            customerProspect.DateUpdatedNext = x.ci.DateUpdatedNext;
                            customerProspect.DateShiftLABLast = x.ci.DateShiftLABLast;
                            customerProspect.DateShiftLABNext = x.ci.DateShiftLABNext;
                            model.CustomerProspectTitulaire1 = customerProspect;
                        }

                        model.IdUserCgp = x.cgp.idUser;

                        lst.Add(model);
                    });

                    lst.ToList().ForEach(delegate(SubscriptionFileModel itm)
                    {
                        if (!sfLst.Any(x => x.IdSubscriptionFile == itm.IdSubscriptionFile))
                        {
                            sfLst.Add(itm);
                        }
                        else
                        {
                            var item = itm != null ? sfLst.FirstOrDefault(x => x.IdSubscriptionFile == itm.IdSubscriptionFile) : null;
                            if (item != null)
                            {
                                if (item.User != null && itm.User != null && item.User.IdDocument.HasValue && item.User.IdDocument != Guid.Empty && item.User.IdDocument == itm.User.IdDocument)
                                {
                                    if (string.IsNullOrEmpty(item.User.UserName))
                                        item.User.UserName = itm.User.UserName;
                                    if (string.IsNullOrEmpty(item.User.UserFirstName))
                                        item.User.UserFirstName = itm.User.UserFirstName;
                                    if (string.IsNullOrEmpty(item.User.UserMobilePhone))
                                        item.User.UserMobilePhone = itm.User.UserMobilePhone;
                                }
                            }
                        }

                    });

                    #region "FILTER"

                    list = sfLst.ToList();

                    list.ForEach(delegate(SubscriptionFileModel sf)
                    {
                        sf.UserCgp = GetUserModelBySubscriptionFile(sf.IdSubscriptionFile);
                    });

                    if (!string.IsNullOrEmpty(letter) && letter.ToUpper() != "TOUS")
                    {
                        list =
                            list.Where(
                                x =>
                                    (x.User != null && x.User.UserName != null && x.User.UserFirstName != null &&
                                     (x.User.UserName.ToLower().StartsWith(letter) || x.User.UserFirstName.ToLower().StartsWith(letter))) ||
                                    (x.FirmInstitution != null && x.FirmInstitution.FirmInstitutionName.ToLower().StartsWith(letter))).ToList();
                    }
                    else if (!string.IsNullOrEmpty(search))
                    {
                        list = list.Where(x =>
                 (x.User != null && x.User.UserName != null && x.User.UserFirstName != null &&
                  (x.User.UserName.ToLower().Contains(search) || x.User.UserFirstName.ToLower().Contains(search))) ||
                 (x.FirmInstitution != null && x.FirmInstitution.FirmInstitutionName.ToLower().Contains(search))).ToList();
                    }
                    #endregion
                }
                // lst = lst;

                
                
                return list.OrderBy(x => x.IdSubscriptionFile).ToViewModel();

            }
        }
Exemplo n.º 8
0
        public static void UpdateProduct(ProductModel productModel)
        {
            using (var db = new UpsilabEntities())
            {                
                var product = db.Product.FirstOrDefault(p => p.IdProduct == productModel.IdProduct);

                product.Name = productModel.Name;
                product.BrochureFilename = productModel.BrochureFilename;
                product.DICIFilename = productModel.DICIFilename;
                product.BrochureLabel = productModel.BrochureLabel;
                product.DICILabel = productModel.DICILabel;
                product.DateUpdated = DateTime.Now;
                product.DatesReportLABObject = (productModel.DateObligationObjetList != null) ? productModel.DateObligationObjetList.ObjectToJson().ToString() : string.Empty;

                if (productModel.IdDocumentModel != null) product.IdDocumentModel = productModel.IdDocumentModel;

                db.SaveChanges();
            }
        }
 public static ProductModel ToViewModel(this Product entity)
 {
     if (entity == null) return null;
     // TODO à remplir
     var productModel = new ProductModel()
     {
         IdProduct = entity.IdProduct,
         IdFirmInstitution = entity.IdFirmInstitution,
         IdDocumentModel = entity.IdDocumentModel,
         Name = entity.Name,
         DICIFilename = entity.DICIFilename,
         BrochureFilename = entity.BrochureFilename,
         DICILabel = entity.DICILabel,
         BrochureLabel = entity.BrochureFilename,
         FirmInstitution = entity.FirmInstitution.ToViewModel(),
         DateObligationObjetList = entity.DatesReportLABObject.JsonToObject().ToList()
     };
     return productModel;
 }