public bool SaveProfileInfo(ProfileInfo req) { MemberAddress ma = Session.Member().MemberAddress() ?? new MemberAddress(); req.CopyPropertiesWithSameName(ma); if (string.IsNullOrWhiteSpace(ma.InvoiceTitle)) { ma.InvoiceTitle = "Default"; } ma.MemberId = Session.MemberId; ma.AddressType = AddressTypes.DefaultAddress; ma.Save(); Member m = Session.Member(); req.CopyPropertiesWithSameName(m); m.Id = Session.MemberId; m.MemberAddressId = ma.Id; m.Save(); return(true); }
public MemberInfo SaveCheckoutAddressInfo(MemberAddressInfo req) { // eğer yeni ziyaretçi ise if (string.IsNullOrWhiteSpace(this.Session.MemberId)) { if (!req.Email.IsEmail()) { throw new APIException("Invalid email address."); } // yeni üye kaydı oluşturalım Member m = Provider.Database.Read <Member>("Email={0}", req.Email); if (m != null) { throw new APIException("The email address is registered. Please login before proceeding.", ErrorTypes.ValidationError, ErrorCodes.ExistingMemberCannotSignUp); } m = new Member(); req.CopyPropertiesWithSameName(m); if (req.FullName.Contains(" ")) { while (req.FullName.Contains(" ")) { req.FullName = req.FullName.Replace(" ", " "); } m.FirstName = req.FullName.Substring(0, req.FullName.IndexOf(' ')); m.LastName = req.FullName.Substring(req.FullName.IndexOf(' ') + 1); } else { m.FirstName = req.FullName; } m.MemberType = MemberTypes.Individual; m.State = MemberStates.WaitingEmailConfirmation; m.ClientId = ApiClient.ClientId; m.Save(); // yeni üyeye email confirmation mesajı m.SendEmailWithPasswordAndConfirmationCode(); // adress kaydını oluşturalım MemberAddress ma = new MemberAddress(); req.CopyPropertiesWithSameName(ma); ma.InvoiceTitle = string.IsNullOrWhiteSpace(ma.InvoiceTitle) ? m.FullName : ma.InvoiceTitle; ma.MemberId = m.Id; ma.Save(); // bu adresi üyenin default adresi yapalım m.MemberAddressId = ma.Id; m.Save(); // sepetini üye kaydıyla ilişkilendirelim var order = Order.GetMemberBasket(); order.MemberAddressId = ma.Id; order.MemberId = m.Id; order.Save(); this.Session.MemberId = m.Id; this.Session.Save(); return(m.ToEntityInfo <MemberInfo>()); } // eğer oturum açılmışsa { // üyede eksik bilgi varsa tamamlayalım Member m = this.Session.Member(); if (string.IsNullOrWhiteSpace(m.FirstName)) // ismi eksikse ekleyelim { if (req.FullName != null && req.FullName.Contains(" ")) { while (req.FullName.Contains(" ")) { req.FullName = req.FullName.Replace(" ", " "); } m.FirstName = req.FullName.Substring(0, req.FullName.IndexOf(' ')); m.LastName = req.FullName.Substring(req.FullName.IndexOf(' ') + 1); } else { m.FirstName = req.FullName; } } if (string.IsNullOrWhiteSpace(m.CompanyInfo)) // firma adı eksikse ekleyelim { m.CompanyInfo = req.InvoiceTitle; } if (string.IsNullOrWhiteSpace(m.PhoneNumber)) // telefon no eksikse ekleyelim { m.PhoneNumber = req.PhoneNumber; } m.Save(); // gönderilen adresi insert ya da update edelim MemberAddress ma = Provider.Database.Read <MemberAddress>("Id={0}", req.Id) ?? new MemberAddress(); req.CopyPropertiesWithSameName(ma); ma.MemberId = m.Id; ma.Save(); // sepetini adresle ilişkilendirelim var order = Order.GetMemberBasket(); order.MemberAddressId = ma.Id; order.MemberId = Session.MemberId; order.Save(); return(m.ToEntityInfo <MemberInfo>()); } }