public void ChangeMentorImage(User user, string path, string type) { UserImage img = context.UserImages.Where(u => u.fk_userId == user.ID).FirstOrDefault(); if (img != null) // edit { img.imagePath = path; img.contentType = type; } else // create new { img = new UserImage(); img.fk_userId = user.ID; img.imagePath = path; img.contentType = type; user.MentorProfile.imgPath = path; context.UserImages.Add(img); } context.SaveChanges(); }
public void RegisterNewUser(RegisterModel regMod) { User user = new User(); user.fname = regMod.FirstName; user.lname = regMod.LastName; user.UserID = regMod.UserName; user.Password = regMod.Password; user.addr1 = regMod.Address1; user.addr2 = regMod.Address2; user.city = regMod.City; user.state = regMod.State; user.zip = regMod.ZipCode; user.phNo = regMod.PhoneNumber; user.user_type = regMod.EnrollAs; context.Users.Add(user); if (regMod.EnrollAs == 1) { MentorProfile mp = new MentorProfile(); mp.description = null; mp.imgPath = "/Uploads/UserImage/m1.jpeg"; mp.major = null; mp.User = user; context.MentorProfiles.Add(mp); List<weekday> weekdays = context.weekdays.Select(w => w).ToList(); List<time> times = context.times.Select(w => w).ToList(); foreach (weekday w in weekdays) { foreach (time t in times) { MentorSchedule ms = new MentorSchedule(); ms.fk_day_Id = w.dayid; ms.fk_time_id = t.timeid; ms.MentorProfile = mp; ms.fk_mentorship_id = null; ms.isMentoring = 0; context.MentorSchedules.Add(ms); } } } else if (regMod.EnrollAs == 2) { StudentProfile mp = new StudentProfile(); mp.description = null; mp.imgPath = "/Uploads/UserImage/m2.jpeg"; mp.clas = null; mp.User = user; context.StudentProfiles.Add(mp); List<weekday> weekdays = context.weekdays.Select(w => w).ToList(); List<time> times = context.times.Select(w => w).ToList(); foreach (weekday w in weekdays) { foreach (time t in times) { StudentSchedule ms = new StudentSchedule(); ms.fk_day_Id = w.dayid; ms.fk_time_id = t.timeid; ms.StudentProfile = mp; ms.fk_mentorship_id = null; context.StudentSchedules.Add(ms); } } } context.SaveChanges(); }