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 });
 }
        //UpdateUserForm
        public object UpdateUserForm(string user, ModelStateDictionary ModelState, string newSignature)
        {
            long user_id = 0;
              try
              {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            UserRegistration usr = serializer.Deserialize<UserRegistration>(user);

            if (!AppHelper.CurrentUser.IsRoot && AppHelper.CurrentUser.ID != usr.ID && (usr.UserType == (byte)Consts.UserTypes.Admin || usr.UserType == (byte)Consts.UserTypes.Root))
              return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "You can't create/update this user.");

            usr.ConfirmPassword = usr.Password;
            usr.ConfirmEmail = usr.Email;
            if (usr.UserType == (byte)Consts.UserTypes.Buyer || usr.UserType == (byte)Consts.UserTypes.HouseBidder)
            {
              usr.CommissionRate = CommissionRate.DefaultCommission;
            }

            if (usr.UserType == (byte)Consts.UserTypes.Seller || usr.UserType == (byte)Consts.UserTypes.SellerBuyer)
              usr.IsPostCards = true;

            usr.ValidateWithoutConfim(ModelState);

            if (ModelState.IsValid)
            {
              if (!UpdateUser(usr))
            return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "The user's information wasn't saved.");
              user_id = usr.ID;
              if (!string.IsNullOrWhiteSpace(newSignature))
              {
            SignatureToImage signature = new SignatureToImage();
            Bitmap signatureImage = signature.SigJsonToImage(newSignature);
            string filePath = DiffMethods.SignatureImagesOnDisk(string.Format("userSignature{0}.png", usr.ID));
            FileInfo fileInfo = new FileInfo(filePath);
            if (fileInfo.Exists) fileInfo.Delete();
            signatureImage.Save(filePath);
              }
            }
            else
            {
              ModelState.Remove("user");
              if (usr.BillingLikeShipping)
              {
            KeyValuePair<string, ModelState>[] res = (from M in ModelState where M.Key.Contains("Shipping") select M).ToArray();
            if (res.Count() > 0)
            {
              foreach (KeyValuePair<string, ModelState> r in res)
                ModelState.Remove(r);
            }
              }
              var errors = (from M in ModelState select new { field = M.Key, message = M.Value.Errors.FirstOrDefault().ErrorMessage }).ToArray();
              return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "Please correct the errors and try again.", errors);
            }
              }
              catch (Exception ex)
              {
            return new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message);
              }
              return new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS, "", user_id);
        }