/// <summary> /// Creates a new user. /// </summary> public ProfileResult CreateProfile(Profile profile) { using (var db = new ProfileDbContext()) { if (db.Profiles.FirstOrDefault(u => u.Email.ToLower() == profile.Email.ToLower()) != null) { return new ProfileResult(new List<string>() { "Email " + profile.Email + " exists already." }); } // wouldn't hurt if we check username here, even though _userManager checks it again if (db.Profiles.FirstOrDefault(u => u.UserName.ToLower() == profile.UserName.ToLower()) != null) { return new ProfileResult(new List<string>() { "Username " + profile.UserName + " is already taken." }); } db.Profiles.Add(profile); db.SaveChanges(); return new ProfileResult { Succeeded = true, ProfileId = profile.Id }; } }
public static ActiveProfileVM Map(Profile profile) { return (profile == null) ? null : new ActiveProfileVM { UserName = profile.UserName, FirstName = profile.FirstName, }; }
public void SetUp() { _service = new ProfileService(); _profile = new Profile() { UserName = Actor.AUTH_USER, Email = "*****@*****.**", FirstName = "Tom", LastName = "Cat", Locations = "Pasadena, CA, USA", Headline = "American chef, author, and television personality", Bio = "He is a cat chef.", BgImg = "A02.jpg", ProfileStyle = ProfileStyle.GetDefault(), }; }
public void SetUp() { _service = new ProfileService(); _profile = new Profile() { UserName = "******", // Note "admin" is a reserved username Email = "*****@*****.**", FirstName = "admin", LastName = "admin", Locations = "", Headline = "", Bio = "", BgImg = "A02.jpg", ProfileStyle = ProfileStyle.GetDefault(), }; }
public new static ProfileVM Map(Profile profile) { return new ProfileVM { Id = profile.Id, // important BgImg = profile.BgImg, BgImgName = profile.BgImg.Split('.')[0], BgImgExt = "." + profile.BgImg.Split('.')[1], UserName = profile.UserName, FirstName = profile.FirstName, LastName = profile.LastName, Styles = profile.ProfileStyle, Headline = profile.Headline, Bio = profile.Bio, Locations = profile.Locations, AllowEmailMe = profile.AllowEmailMe, }; }
public void UpdateProfile(string userName, Profile profile) { using (var db = new ProfileDbContext()) { var ent = db.Profiles.FirstOrDefault(p => p.UserName.Equals(userName, StringComparison.InvariantCultureIgnoreCase)); if (ent == null) return; bool changed = false; if (!profile.FirstName.IsNullOrEmpty() && ent.FirstName != profile.FirstName) { ent.FirstName = profile.FirstName; changed = true; } if (!profile.LastName.IsNullOrEmpty() && ent.LastName != profile.LastName) { ent.LastName = profile.LastName; changed = true; } if (!profile.Headline.IsNullOrEmpty() && ent.Headline != profile.Headline) { ent.Headline = profile.Headline; changed = true; } if (!profile.Bio.IsNullOrEmpty() && ent.Bio != profile.Bio) { ent.Bio = profile.Bio; changed = true; } if (!profile.Locations.IsNullOrEmpty() && ent.Locations != profile.Locations) { ent.Locations = profile.Locations; changed = true; } if (changed) db.SaveChanges(); } }