public ActionResult ImageUpload(HttpPostedFileBase upload) { if (upload != null) { var photo = new byte[upload.ContentLength]; upload.InputStream.Read(photo, 0, upload.ContentLength); using (EduPortalContext context = new EduPortalContext()) { var email = User.Identity.Name; var profile = context.Profiles.Where(p => p.Email == email).FirstOrDefault(); profile.Photo = photo; context.SaveChanges(); } } return(Index()); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { UserProfile profile = null; using (EduPortalContext db = new EduPortalContext()) { profile = db.Profiles.FirstOrDefault(u => u.Email == model.Email); } if (profile == null) { // создаем нового пользователя using (EduPortalContext db = new EduPortalContext()) { if (model.IsTeacher) { db.Profiles.Add(new Teacher(model.Email, model.Password, model.FirstName, model.SecondName, model.DateOfBirth, model.City)); } else { db.Profiles.Add(new Student(model.Email, model.Password, model.FirstName, model.SecondName, model.DateOfBirth, model.City)); } db.SaveChanges(); profile = db.Profiles.Where(u => u.Email == model.Email && u.Password == model.Password).FirstOrDefault(); } // если пользователь удачно добавлен в бд if (profile != null) { FormsAuthentication.SetAuthCookie(model.Email, true); return(RedirectToAction("Index", "Profile")); } } else { ModelState.AddModelError("", "Пользователь с таким логином уже существует"); } } return(View(model)); }