예제 #1
0
        //GetUserDataJSON
        public object GetUserDataJSON(long user_id)
        {
            User user = dataContext.Users.SingleOrDefault(U => U.ID == user_id);

            if (user == null)
            {
                return(null);
            }
            string   filePath = DiffMethods.SignatureImagesOnDisk(string.Format("userSignature{0}.png", user.ID));
            FileInfo fileInfo = new FileInfo(filePath);
            var      jsonData = new
            {
                user_id        = user.ID,
                login          = user.Login,
                pw             = user.PasswordEncrypted,
                usertype       = user.UserType_ID,
                status         = user.UserStatus_ID,
                commrate       = user.CommissionRate_ID,
                email          = user.Email,
                datein         = user.DateRegistered.ToString(),
                isconfirmed    = user.IsConfirmed,
                ismodifyed     = user.IsModifyed,
                dph            = user.DayPhone,
                eph            = user.EveningPhone,
                mph            = user.MobilePhone,
                fax            = user.Fax,
                tax            = user.TaxpayerID,
                ip             = user.IP,
                lastattempt    = (user.LastAttempt.HasValue) ? user.LastAttempt.Value.ToString() : "",
                failedattempts = (user.FailedAttempts.HasValue) ? user.FailedAttempts.Value : 0,
                rws            = user.RecieveWeeklySpecials,
                rnu            = user.RecieveNewsUpdates,
                rbc            = user.IsRecievingBidConfirmation,
                robn           = user.IsRecievingOutBidNotice,
                rlsn           = user.IsRecievingLotSoldNotice,
                rlcn           = user.IsRecievingLotClosedNotice,
                notes          = user.Notes ?? String.Empty,
                isnotseller    = user.IsSellerType,
                ispwdisapled   = AppHelper.CurrentUser.IsAdmin && (user.IsAdmin || user.IsRoot) && AppHelper.CurrentUser.ID != user.ID,
                ah1            = (user.UserReference_1 != null) ? user.UserReference_1.AuctionHouse : String.Empty,
                pn1            = (user.UserReference_1 != null) ? user.UserReference_1.PhoneNumber : String.Empty,
                lbd1           = (user.UserReference_1 != null) ? user.UserReference_1.LastBidPlaced : String.Empty,
                ah2            = (user.UserReference_2 != null) ? user.UserReference_2.AuctionHouse : String.Empty,
                pn2            = (user.UserReference_2 != null) ? user.UserReference_2.PhoneNumber : String.Empty,
                lbd2           = (user.UserReference_2 != null) ? user.UserReference_2.LastBidPlaced : String.Empty,
                ebid           = user.EbayID,
                evf            = user.EbayFeedback,
                iscatalog      = user.IsCatalog,
                ispostcards    = user.IsPostCards,
                b_first        = (user.Billing_AddressCard_ID.HasValue) ? user.AddressCard_Billing.FirstName : String.Empty,
                b_middle       = (user.Billing_AddressCard_ID.HasValue) ? user.AddressCard_Billing.MiddleName : String.Empty,
                b_last         = (user.Billing_AddressCard_ID.HasValue) ? user.AddressCard_Billing.LastName : String.Empty,
                b_comp         = (user.Billing_AddressCard_ID.HasValue) ? user.AddressCard_Billing.Company : String.Empty,
                b_addr1        = (user.Billing_AddressCard_ID.HasValue) ? user.AddressCard_Billing.Address1 : String.Empty,
                b_addr2        = (user.Billing_AddressCard_ID.HasValue) ? user.AddressCard_Billing.Address2 : String.Empty,
                b_city         = (user.Billing_AddressCard_ID.HasValue) ? user.AddressCard_Billing.City : String.Empty,
                b_state        = (user.Billing_AddressCard_ID.HasValue) ? user.AddressCard_Billing.State_ID : 0,
                b_zip          = (user.Billing_AddressCard_ID.HasValue) ? user.AddressCard_Billing.Zip : String.Empty,
                b_country      = (user.Billing_AddressCard_ID.HasValue) ? user.AddressCard_Billing.Country_ID : 1,
                b_istate       = (user.Billing_AddressCard_ID.HasValue) ? user.AddressCard_Billing.InternationalState : String.Empty,
                bls            = user.BillingLikeShipping,
                s_first        = (user.AddressBillingLikeShipping != null) ? user.AddressBillingLikeShipping.FirstName : String.Empty,
                s_middle       = (user.AddressBillingLikeShipping != null) ? user.AddressBillingLikeShipping.MiddleName : String.Empty,
                s_last         = (user.AddressBillingLikeShipping != null) ? user.AddressBillingLikeShipping.LastName : String.Empty,
                s_comp         = (user.AddressBillingLikeShipping != null) ? user.AddressBillingLikeShipping.Company : String.Empty,
                s_addr1        = (user.AddressBillingLikeShipping != null) ? user.AddressBillingLikeShipping.Address1 : String.Empty,
                s_addr2        = (user.AddressBillingLikeShipping != null) ? user.AddressBillingLikeShipping.Address2 : String.Empty,
                s_city         = (user.AddressBillingLikeShipping != null) ? user.AddressBillingLikeShipping.City : String.Empty,
                s_state        = (user.AddressBillingLikeShipping != null) ? user.AddressBillingLikeShipping.State_ID : 0,
                s_zip          = (user.AddressBillingLikeShipping != null) ? user.AddressBillingLikeShipping.Zip : String.Empty,
                s_country      = (user.AddressBillingLikeShipping != null) ? user.AddressBillingLikeShipping.Country_ID : 1,
                s_istate       = (user.AddressBillingLikeShipping != null) ? user.AddressBillingLikeShipping.InternationalState : String.Empty,
                showSignature  = user.UserType_ID == (byte)Consts.UserTypes.Specialist || user.UserType_ID == (byte)Consts.UserTypes.SpecialistViewer,
                signatureUrl   = fileInfo.Exists ? DiffMethods.SignatureImagesWeb(fileInfo.Name) : DiffMethods.PublicImages("blank_image.jpg")
            };

            return(jsonData);
        }
예제 #2
0
        //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));
        }
 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)));
     }
 }