public void Create() { Profile profile = new Profile { ProfileId = 10000, UserId = "TestUserId", FirstName = "testFN", LastName = "testLN", Country = "testCoun", City = "tedtCity", School = "testSchool", Degree = "testDeg", About = "testAbout" }; repo.SaveProfile(profile); var result = repo.GetProfileByUserId("TestUserId"); Assert.IsNotNull(result.ProfileId); Assert.AreEqual("TestUserId", result.UserId); Assert.AreEqual("testFN", result.FirstName); Assert.AreEqual("testLN", result.LastName); Assert.AreEqual("testCoun", result.Country); Assert.AreEqual("tedtCity", result.City); Assert.AreEqual("testSchool", result.School); Assert.AreEqual("testDeg", result.Degree); Assert.AreEqual("testAbout", result.About); Assert.IsNull(result.Age); Assert.IsNull(result.UserImage); }
public Profile SaveProfile(Profile profile) { Profile newProfile = db.Profiles.Add(profile); db.SaveChanges(); if(profile.Files.SingleOrDefault<File>() != null) { profile.UserImage = profile.Files.SingleOrDefault<File>().Id; db.SaveChanges(); } return newProfile; }
public void UpdateProfile(Profile profile) { File newImg; if (profile.UserImage > 0) { db.Files.Remove(profile.Files.First(f => f.Id == profile.UserImage)); } newImg = profile.Files.FirstOrDefault(); if(newImg != null) { newImg.ProfileId = profile.ProfileId; db.Files.Add(newImg); db.SaveChanges(); profile.UserImage = newImg.Id; } db.Entry(profile).State = EntityState.Modified; db.SaveChanges(); }
public static void SetupClass(TestContext testContext) { ProfileRepository repo = new ProfileRepository(); Profile profile = new Profile { UserId = "TestUserIdDelete", }; repo.SaveProfile(profile); profile = new Profile { UserId = "TestUserIdSearch", }; repo.SaveProfile(profile); }
// POST: api/ProfilesService public void PostProfile(Profile profile) { repo.SaveProfile(profile); }
// PUT: api/ProfilesService/5 public void PutProfile(Profile profile) { repo.UpdateProfile(profile); }
public ProfileModel ConvertToModel(Profile profile) { ProfileModel profileM = new ProfileModel() { ProfileId = profile.ProfileId, UserId = profile.UserId, Age = profile.Age, FirstName = profile.FirstName, LastName = profile.LastName, Degree = profile.Degree, City = profile.City, Country = profile.Country, School = profile.School, UserImage = profile.UserImage, About = profile.About, }; return profileM; }
public async Task<ActionResult> Create() { string userId = User.Identity.GetUserId(); ProfileRepository repo = new ProfileRepository(); Profile newProfile = new Profile { UserId = User.Identity.GetUserId() }; newProfile = repo.SaveProfile(newProfile); //Profile profile = new Profile { UserId = User.Identity.GetUserId() }; return View(newProfile); }
public void Update() { Profile profile = new Profile { UserId = "TestUserId2", }; profile = repo.SaveProfile(profile); if (profile != null) { Assert.IsNotNull(profile.ProfileId); Assert.AreEqual("TestUserId2", profile.UserId); Assert.IsNull(profile.FirstName); Assert.IsNull(profile.LastName); Assert.IsNull(profile.Country); Assert.IsNull(profile.City); Assert.IsNull(profile.School); Assert.IsNull(profile.Degree); Assert.IsNull(profile.About); Assert.IsNull(profile.Age); Assert.IsNull(profile.UserImage); profile.FirstName = "testFN2"; profile.LastName = "testLN2"; profile.Country = "testCoun2"; profile.City = "tedtCity2"; repo.UpdateProfile(profile); var result = repo.GetProfileByUserId("TestUserId2"); Assert.IsNotNull(result.ProfileId); Assert.AreEqual("TestUserId2", result.UserId); Assert.AreEqual("testFN2", result.FirstName); Assert.AreEqual("testLN2", result.LastName); Assert.AreEqual("testCoun2", result.Country); Assert.AreEqual("tedtCity2", result.City); Assert.IsNull(result.School); Assert.IsNull(result.Degree); Assert.IsNull(result.About); Assert.IsNull(result.Age); Assert.IsNull(result.UserImage); } }