コード例 #1
0
 public JsonResult SignConsignmentContract(long id, string sellerSignature)
 {
     try
     {
         Consignment         consignment         = InvoiceRepository.GetConsignment(id);
         ConsignmentContract consignmentContract = InvoiceRepository.GetConsignmentContract(id);
         if (consignment == null || consignmentContract == null || consignmentContract.StatusID != (int)Consts.ConsignmentContractStatus.Unsigned || consignment.User_ID != AppHelper.CurrentUser.ID)
         {
             throw new Exception("Error occurred during the process of signing the document. Please reload page and try again");
         }
         if (string.IsNullOrWhiteSpace(sellerSignature))
         {
             throw new Exception("Draw signature as first.");
         }
         Specialist specialist = InvoiceRepository.GetSpecialist(consignment.Specialist_ID.GetValueOrDefault(-1));
         if (specialist == null)
         {
             throw new Exception("Error occurred during the process of signing the document. Please contact us.");
         }
         string   lelandsSignaturePath = AppHelper.SignatureImagesOnDisk(string.Format("userSignature{0}.png", specialist.User_ID));
         FileInfo fileInfo             = new FileInfo(lelandsSignaturePath);
         if (!fileInfo.Exists)
         {
             throw new Exception("Error occurred during the process of signing the document. Please contact us.");
         }
         SignatureToImage signature           = new SignatureToImage();
         Bitmap           signatureImage      = signature.SigJsonToImage(sellerSignature);
         string           sellerSignaturePath = AppHelper.ConsignmentContractOnDisk(consignment.ID, consignmentContract.FileName.ToLower().Replace(".pdf", ".png"));
         fileInfo = new FileInfo(sellerSignaturePath);
         if (fileInfo.Exists)
         {
             fileInfo.Delete();
         }
         signatureImage.Save(sellerSignaturePath);
         Address lelandsAddress = new Address
         {
             FirstName = "Lelands.com",
             LastName  = Consts.SiteEmail,
             Address_1 = Consts.CompanyAddress,
             City      = Consts.CompanyCity,
             State     = Consts.CompanyState,
             Zip       = Consts.CompanyZip,
             HomePhone = Consts.CompanyPhone,
             WorkPhone = Consts.CompanyFax
         };
         User    consignor        = UserRepository.GetUser(consignment.User_ID, true);
         Address consignorAddress = Address.GetAddress(UserRepository.GetAddressCard(consignor.Billing_AddressCard_ID.GetValueOrDefault(0), true));
         PdfReports.ConsignmentContract(AppHelper.ConsignmentContractOnDisk(consignment.ID, consignmentContract.FileName), AppHelper.PublicImagesOnDisk("logo.png"), string.Empty, Consts.CompanyTitleName, string.Empty, lelandsAddress, lelandsSignaturePath, consignorAddress, consignor.Email, sellerSignaturePath, DateTime.Now, InvoiceRepository.GetConsignmentDetailsByConsignmentID(id), consignmentContract.ContractText);
         consignmentContract.StatusID = (int)Consts.ConsignmentContractStatus.Signed;
         InvoiceRepository.UpdateConsignmentContract(consignmentContract);
     }
     catch (Exception exc)
     {
         return(JSON(new { success = false, exc.Message }));
     }
     return(JSON(new { success = true }));
 }
コード例 #2
0
 public JsonResult UpdateConsignmentContractText(long consignmentID, string contractText)
 {
     try
     {
         var consignment = AuctionRepository.GetConsignment(consignmentID);
         if (consignment == null)
         {
             throw new Exception("Consignment does not exist.");
         }
         var consignmentContract = AuctionRepository.GetConsignmentContract(consignmentID);
         if (consignmentContract == null)
         {
             throw new Exception("Consignment does not exist.");
         }
         if (consignmentContract.StatusID == (int)Consts.ConsignmentContractStatus.Signed)
         {
             throw new Exception("The contract is already signed by seller.");
         }
         consignmentContract.ContractText = contractText;
         var fileName   = string.Format("CA{0}.pdf", DateTime.Now.Ticks);
         var specialist = AuctionRepository.GetSpecialist(consignment.Specialist_ID.GetValueOrDefault(-1));
         if (specialist == null)
         {
             throw new Exception("Set specialist at first.");
         }
         var lelandsSignaturePath =
             DiffMethods.SignatureImagesOnDisk(string.Format("userSignature{0}.png", specialist.User_ID));
         var fileInfo = new FileInfo(lelandsSignaturePath);
         if (!fileInfo.Exists)
         {
             throw new Exception("You can't generate contract without specialist signature.");
         }
         if (!string.IsNullOrWhiteSpace(consignmentContract.FileName))
         {
             fileInfo =
                 new FileInfo(DiffMethods.ConsignmentContractOnDisk(consignment.ID, consignmentContract.FileName));
             if (fileInfo.Exists)
             {
                 fileInfo.Delete();
             }
         }
         var lelandsAddress = new Address
         {
             FirstName = "Lelands.com",
             LastName  = Consts.SiteEmail,
             Address_1 = Consts.CompanyAddress,
             City      = Consts.CompanyCity,
             State     = Consts.CompanyState,
             Zip       = Consts.CompanyZip,
             HomePhone = Consts.CompanyPhone,
             WorkPhone = Consts.CompanyFax
         };
         var consignor        = consignment.User;
         var consignorAddress = Address.GetAddress(consignor.AddressCard_Billing);
         var items            = AuctionRepository.GetAuctionsListByConsignor(consignment.ID);
         PdfReports.ConsignmentContract(DiffMethods.ConsignmentContractOnDisk(consignment.ID, fileName),
                                        DiffMethods.PublicImagesOnDisk("logo.png"), string.Empty, Consts.CompanyTitleName, string.Empty,
                                        lelandsAddress, lelandsSignaturePath, consignorAddress, consignor.Email, string.Empty, DateTime.Now,
                                        items, consignmentContract.ContractText);
         consignmentContract.UpdateFields(consignmentContract.ConsignmentID,
                                          (int)Consts.ConsignmentContractStatus.Unsigned, consignmentContract.ContractText, fileName);
         AuctionRepository.UpdateConsignmentContract(consignmentContract);
         return
             (JSON(new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS, "Contract was generated successfully.",
                                         new
         {
             StatusText = Consts.ConsignmentContractStatus.Unsigned.ToString(),
             DownloadLink =
                 Url.Action("GetConsignmentContract", "Auction", new { consignmentID = consignment.ID }),
             ShowLink =
                 Url.Action("ShowConsignmentContract", "Auction", new { consignmentID = consignment.ID })
         })));
     }
     catch (Exception exc)
     {
         return(JSON(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, exc.Message)));
     }
 }