Beispiel #1
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));
        }
Beispiel #2
0
        //UpdateUser
        public bool UpdateUser(UserRegistration info)
        {
            bool newUser = info.ID < 1;
            User user    = (!newUser) ? GetUser(info.ID) : new User();

            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    if (newUser)
                    {
                        dataContext.Users.InsertOnSubmit(user);
                    }
                    user.Login             = info.Login;
                    user.Password          = info.Password;
                    user.UserType_ID       = info.UserType;
                    user.UserStatus_ID     = info.UserStatus;
                    user.CommissionRate_ID = info.CommissionRate;
                    user.Email             = info.Email;
                    user.DateRegistered    = (newUser) ? DateTime.Now : user.DateRegistered;
                    user.IsConfirmed       = info.IsConfirmed;
                    user.IsModifyed        = info.IsModifyed;
                    user.DayPhone          = info.DayPhone;
                    user.EveningPhone      = info.EveningPhone;
                    user.MobilePhone       = info.MobilePhone;
                    user.Fax                        = info.Fax;
                    user.TaxpayerID                 = info.Tax;
                    user.FailedAttempts             = info.FaildAttempts;
                    user.RecieveWeeklySpecials      = info.RecieveWeeklySpecials;
                    user.RecieveNewsUpdates         = info.RecieveNewsUpdates;
                    user.IsRecievingBidConfirmation = info.RecieveBidConfirmation;
                    user.IsRecievingOutBidNotice    = info.RecieveOutBidNotice;
                    user.IsRecievingLotClosedNotice = info.RecieveLotClosedNotice;
                    user.IsRecievingLotSoldNotice   = info.RecieveLotSoldNotice;
                    user.EbayID                     = info.eBayBidderID;
                    user.EbayFeedback               = info.eBayFeedback;
                    user.Notes                      = info.Notes;
                    user.IsCatalog                  = info.IsCatalog;
                    user.IsPostCards                = info.IsPostCards;

                    AddressCard ac = (newUser || user.AddressCard_Billing == null) ? new AddressCard() : user.AddressCard_Billing;
                    ac.FirstName          = info.BillingFirstName;
                    ac.MiddleName         = info.BillingMiddleName;
                    ac.LastName           = info.BillingLastName;
                    ac.Company            = info.BillingCompany;
                    ac.Address1           = info.BillingAddress1;
                    ac.Address2           = info.BillingAddress2;
                    ac.City               = info.BillingCity;
                    ac.State              = info.BillingState;
                    ac.State_ID           = info.BillingState_ID;
                    ac.Zip                = info.BillingZip;
                    ac.Country_ID         = info.BillingCountry;
                    ac.InternationalState = info.BillingInternationalState;
                    if (newUser || user.AddressCard_Billing == null)
                    {
                        dataContext.AddressCards.InsertOnSubmit(ac);
                        user.AddressCard_Billing = ac;
                    }

                    user.BillingLikeShipping = info.BillingLikeShipping;

                    ac                    = (newUser || user.AddressCard_Shipping == null) ? new AddressCard() : user.AddressCard_Shipping;
                    ac.FirstName          = (info.BillingLikeShipping) ? info.BillingFirstName : info.ShippingFirstName;
                    ac.MiddleName         = (info.BillingLikeShipping) ? info.BillingMiddleName : info.ShippingMiddleName;
                    ac.LastName           = (info.BillingLikeShipping) ? info.BillingLastName : info.ShippingLastName;
                    ac.Company            = (info.BillingLikeShipping) ? info.BillingCompany : info.ShippingCompany;
                    ac.Address1           = (info.BillingLikeShipping) ? info.BillingAddress1 : info.ShippingAddress1;
                    ac.Address2           = (info.BillingLikeShipping) ? info.BillingAddress2 : info.ShippingAddress2;
                    ac.City               = (info.BillingLikeShipping) ? info.BillingCity : info.ShippingCity;
                    ac.State              = (info.BillingLikeShipping) ? info.BillingState : info.ShippingState;
                    ac.State_ID           = (info.BillingLikeShipping) ? info.BillingState_ID : info.ShippingState_ID;
                    ac.Zip                = (info.BillingLikeShipping) ? info.BillingZip : info.ShippingZip;
                    ac.Country_ID         = (info.BillingLikeShipping) ? info.BillingCountry : info.ShippingCountry;
                    ac.InternationalState = (info.BillingLikeShipping) ? info.BillingInternationalState : info.ShippingInternationalState;
                    if (newUser || user.AddressCard_Shipping == null)
                    {
                        dataContext.AddressCards.InsertOnSubmit(ac);
                        user.AddressCard_Shipping = ac;
                    }

                    UserReference ur = (newUser || user.UserReference_1 == null) ? new UserReference() : user.UserReference_1;
                    ur.AuctionHouse  = info.AuctionHouse1;
                    ur.PhoneNumber   = info.PhoneNumber1;
                    ur.LastBidPlaced = info.LastBidDate1;
                    if (newUser || user.UserReference_1 == null)
                    {
                        dataContext.UserReferences.InsertOnSubmit(ur);
                        user.UserReference_1 = ur;
                    }

                    ur = (newUser || user.UserReference_2 == null) ? new UserReference() : user.UserReference_2;
                    ur.AuctionHouse  = info.AuctionHouse2;
                    ur.PhoneNumber   = info.PhoneNumber2;
                    ur.LastBidPlaced = info.LastBidDate2;
                    if (newUser || user.UserReference_2 == null)
                    {
                        dataContext.UserReferences.InsertOnSubmit(ur);
                        user.UserReference_2 = ur;
                    }

                    GeneralRepository.SubmitChanges(dataContext);
                    ts.Complete();
                    info.ID = user.ID;
                }
            }
            catch (ChangeConflictException cce)
            {
                Logger.LogException(cce);
                throw cce;
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                throw ex;
            }
            return(true);
        }
        //UpdateUser
        public bool UpdateUser(UserRegistration info)
        {
            bool newUser = info.ID < 1;
              User user = (!newUser) ? GetUser(info.ID) : new User();
              try
              {
            using (TransactionScope ts = new TransactionScope())
            {
              if (newUser) dataContext.Users.InsertOnSubmit(user);
              user.Login = info.Login;
              user.Password = info.Password;
              user.UserType_ID = info.UserType;
              user.UserStatus_ID = info.UserStatus;
              user.CommissionRate_ID = info.CommissionRate;
              user.Email = info.Email;
              user.DateRegistered = (newUser) ? DateTime.Now : user.DateRegistered;
              user.IsConfirmed = info.IsConfirmed;
              user.IsModifyed = info.IsModifyed;
              user.DayPhone = info.DayPhone;
              user.EveningPhone = info.EveningPhone;
              user.MobilePhone = info.MobilePhone;
              user.Fax = info.Fax;
              user.TaxpayerID = info.Tax;
              user.FailedAttempts = info.FaildAttempts;
              user.RecieveWeeklySpecials = info.RecieveWeeklySpecials;
              user.RecieveNewsUpdates = info.RecieveNewsUpdates;
              user.IsRecievingBidConfirmation = info.RecieveBidConfirmation;
              user.IsRecievingOutBidNotice = info.RecieveOutBidNotice;
              user.IsRecievingLotClosedNotice = info.RecieveLotClosedNotice;
              user.IsRecievingLotSoldNotice = info.RecieveLotSoldNotice;
              user.EbayID = info.eBayBidderID;
              user.EbayFeedback = info.eBayFeedback;
              user.Notes = info.Notes;
              user.IsCatalog = info.IsCatalog;
              user.IsPostCards = info.IsPostCards;

              AddressCard ac = (newUser || user.AddressCard_Billing == null) ? new AddressCard() : user.AddressCard_Billing;
              ac.FirstName = info.BillingFirstName;
              ac.MiddleName = info.BillingMiddleName;
              ac.LastName = info.BillingLastName;
              ac.Company = info.BillingCompany;
              ac.Address1 = info.BillingAddress1;
              ac.Address2 = info.BillingAddress2;
              ac.City = info.BillingCity;
              ac.State = info.BillingState;
              ac.State_ID = info.BillingState_ID;
              ac.Zip = info.BillingZip;
              ac.Country_ID = info.BillingCountry;
              ac.InternationalState = info.BillingInternationalState;
              if (newUser || user.AddressCard_Billing == null)
              {
            dataContext.AddressCards.InsertOnSubmit(ac);
            user.AddressCard_Billing = ac;
              }

              user.BillingLikeShipping = info.BillingLikeShipping;

              ac = (newUser || user.AddressCard_Shipping == null) ? new AddressCard() : user.AddressCard_Shipping;
              ac.FirstName = (info.BillingLikeShipping) ? info.BillingFirstName : info.ShippingFirstName;
              ac.MiddleName = (info.BillingLikeShipping) ? info.BillingMiddleName : info.ShippingMiddleName;
              ac.LastName = (info.BillingLikeShipping) ? info.BillingLastName : info.ShippingLastName;
              ac.Company = (info.BillingLikeShipping) ? info.BillingCompany : info.ShippingCompany;
              ac.Address1 = (info.BillingLikeShipping) ? info.BillingAddress1 : info.ShippingAddress1;
              ac.Address2 = (info.BillingLikeShipping) ? info.BillingAddress2 : info.ShippingAddress2;
              ac.City = (info.BillingLikeShipping) ? info.BillingCity : info.ShippingCity;
              ac.State = (info.BillingLikeShipping) ? info.BillingState : info.ShippingState;
              ac.State_ID = (info.BillingLikeShipping) ? info.BillingState_ID : info.ShippingState_ID;
              ac.Zip = (info.BillingLikeShipping) ? info.BillingZip : info.ShippingZip;
              ac.Country_ID = (info.BillingLikeShipping) ? info.BillingCountry : info.ShippingCountry;
              ac.InternationalState = (info.BillingLikeShipping) ? info.BillingInternationalState : info.ShippingInternationalState;
              if (newUser || user.AddressCard_Shipping == null)
              {
            dataContext.AddressCards.InsertOnSubmit(ac);
            user.AddressCard_Shipping = ac;
              }

              UserReference ur = (newUser || user.UserReference_1 == null) ? new UserReference() : user.UserReference_1;
              ur.AuctionHouse = info.AuctionHouse1;
              ur.PhoneNumber = info.PhoneNumber1;
              ur.LastBidPlaced = info.LastBidDate1;
              if (newUser || user.UserReference_1 == null)
              {
            dataContext.UserReferences.InsertOnSubmit(ur);
            user.UserReference_1 = ur;
              }

              ur = (newUser || user.UserReference_2 == null) ? new UserReference() : user.UserReference_2;
              ur.AuctionHouse = info.AuctionHouse2;
              ur.PhoneNumber = info.PhoneNumber2;
              ur.LastBidPlaced = info.LastBidDate2;
              if (newUser || user.UserReference_2 == null)
              {
            dataContext.UserReferences.InsertOnSubmit(ur);
            user.UserReference_2 = ur;
              }

              GeneralRepository.SubmitChanges(dataContext);
              ts.Complete();
              info.ID = user.ID;
            }
              }
              catch (ChangeConflictException cce)
              {
            Logger.LogException(cce);
            throw cce;
              }
              catch (Exception ex)
              {
            Logger.LogException(ex);
            throw ex;
              }
              return true;
        }