static void Main(string[] args) { //Creating cumstomers customerProfile customer1 = new customerProfile(); customer1.first_Name = "James"; customer1.last_Name = "Nelson"; customer1.age = 19; customer1.member_Status = false; customerProfile customer2 = new customerProfile(); customer2.first_Name = "Huck"; customer2.last_Name = "Doneldson"; customer2.age = 30; customer2.member_Status = false; customerProfile customer3 = new customerProfile(); customer3.first_Name = "Jen"; customer3.last_Name = "Carry"; customer3.age = 25; customer3.member_Status = true; customerProfile[] allcustomerProfiles = { customer1, customer2, customer3 }; for (int i = 0; i < allcustomerProfiles.Length; i++) { //checking customer age if (allcustomerProfiles[i].age < 21) { Console.WriteLine("Customer " + allcustomerProfiles[i].first_Name + " " + allcustomerProfiles[i].last_Name + " is not of legal age to order."); } else { Console.WriteLine("Customer " + allcustomerProfiles[i].first_Name + " " + allcustomerProfiles[i].last_Name + " may place an order."); } //checking customer membership status if (allcustomerProfiles[i].member_Status == true) { Console.WriteLine("Customer " + allcustomerProfiles[i].first_Name + " " + allcustomerProfiles[i].last_Name + " is a Premium Member."); } else { Console.WriteLine("Customer " + allcustomerProfiles[i].first_Name + " " + allcustomerProfiles[i].last_Name + " is a Standard Member."); } } }
public void Add(IWebshipAccount item) { // // by convention new users are added to the newusers table, and // then added to the userprofile table // I believe newusers served a role in a manual process before, but am unsure // Mapper.Reset(); Mapper.CreateMap <IWebshipAccount, NewUser>() .ForMember(dest => dest.Created, opt => opt.Ignore()) .ForMember(dest => dest.CreatedDate, opt => opt.Ignore()) .ForMember(dest => dest.RequestDate, opt => opt.Ignore()); var newuser = Mapper.Map <IWebshipAccount, NewUser>(item); Mapper.AssertConfigurationIsValid(); // Fill in data not automapped newuser.CreatedDate = DateTime.Now; newuser.RequestDate = DateTime.Now; newuser.Created = true; // Per Bill set this to easily recognizable value newuser.CreatedBy = -1; _Db.NewUsers.InsertOnSubmit(newuser); // // The userprofile row is where the "webship account" is stored // var userprofile = new UserProfile(); // We need access to the underlying implementation var actualitem = (WebshipAccount)item; actualitem.CreatedFrom = userprofile; // this empty userprofile will be updated in the factory below new WebshipAccountNewDefaults().SetDefaults(actualitem); WebshipAccountFactory.Update(actualitem); // queue for storage in DB _Db.UserProfiles.InsertOnSubmit(userprofile); // there must be a row in customerProfiles to schedule a pickup // for now, leaving this awkwardness here since moving it would // make error handling that much harder customerProfile cp = null; var cprofile = from p in _Db.customerProfiles where p.CustID == item.CustID select p; if (!cprofile.Any()) { // create customerprofile row cp = new customerProfile { AccountLockout = false, CustContactPhone = item.CompanyPhone, CustID = item.CustID, CustName = item.CompanyName, PhyAddress1 = item.CompanyAddress1, PhyAddress2 = item.CompanyAddress2, KnownShipper = false, PhyCity = item.CompanyCity, PhyState = item.CompanyState, PhyZip = item.CompanyZip }; _Db.customerProfiles.InsertOnSubmit(cp); } // check to see if this object will fit into the DB columns try { _Db.TestSubmitChanges(); } catch (InvalidOperationException ex) { // discard the changes _Db.DiscardInsertsAndDeletes(); _Db.SubmitChanges(); // rethrow the exception for the benefit of our caller); throw; } // If we made it to here, we can proceed safely // Get a new UID from the DB int?newUid = 0; _Db.sp_getuid(ref newUid); if (!newUid.HasValue || newUid == 0) { // discard the changes _Db.DiscardInsertsAndDeletes(); _Db.SubmitChanges(); throw new CannotCreateNewIdException("WebshipAccountRepository.Add: sp_getuid returned null or zero for the next UID"); } // store customer id into objects before storing them in the DB newuser.UID = newUid.Value; item.UID = newUid.Value; actualitem.CreatedFrom.UID = newUid.Value; _Db.SubmitChanges(); }