public static Boolean createAccount(string email, string first, string last, string password, string gender, DateTime birthday) { try { SIEBUEntities db = new SIEBUEntities(); if (db.Users.Where(u => u.email == email).Count() == 0) { //populate user object with general information User n_customer = new User(); n_customer.email = email; n_customer.firstName = first; n_customer.lastName = last; n_customer.dob = birthday; n_customer.joindate = DateTime.Now; n_customer.gender = (gender == "female") ? true : false; // encryption/salt creation byte[] salt = new byte[48]; new RNGCryptoServiceProvider().GetBytes(salt); n_customer.salt = salt; n_customer.password = encrypt(email, password, salt); db.Users.Add(n_customer); db.SaveChanges(); return true; } return false; } catch (Exception e) { Console.WriteLine("The Error is " + e.ToString()); return false; } }
//get User from Entity public UserModel(User u, SIEBUEntities db = null) { if (db == null) db = new SIEBUEntities(); first_name = u.firstName; last_name = u.lastName; location = u.location; profile_image = u.profileimg_url; //u.User_ProfileImage.FirstOrDefault().url; contact_email = (u.User_Contact.Any(c => c.Contact.caption == "Email Address") ? u.User_Contact.FirstOrDefault(c => c.Contact.caption == "Email Address").value : ""); website = (u.User_Contact.Any(c => c.Contact.caption == "Website") ? u.User_Contact.FirstOrDefault(c => c.Contact.caption == "Website").value : ""); social_media = SocialMediaModel.getSocialMedia(u, db); if (u.gender.HasValue) gender = (u.gender.Value == true ? "Female" : "Male"); if (u.dob.HasValue && u.dob != DateTime.MinValue) age = calculateAge(u.dob.Value); }
public static List<SubscriptionModel> getSubscriptions(User subscriber) { List<SubscriptionModel> subscriptions = new List<SubscriptionModel>(); foreach (User_StoreSubscription sub in subscriber.User_StoreSubscription) subscriptions.Add(new SubscriptionModel(sub)); return subscriptions; }
public static List<SocialMediaModel> getSocialMedia(User u, SIEBUEntities db = null) { if (db == null) db = new SIEBUEntities(); List<SocialMediaModel> output = new List<SocialMediaModel>(); foreach (Contact sm_type in db.Contacts.Where(c => c.is_socialmedia == true)) { SocialMediaModel smodel = new SocialMediaModel(sm_type); smodel.url = (u.User_Contact.Any(m => m.social_media == sm_type.sm_id) ? u.User_Contact.FirstOrDefault(m => m.social_media == sm_type.sm_id).value : null); output.Add(smodel); } return output; }