public async Task <IActionResult> Register(Customer c) { if (ModelState.IsValid) { Customer customer = await _cc.Customer.FirstOrDefaultAsync(u => u.Login == c.Login || u.Email == c.Email || u.Phone == c.Phone); if (customer == null) { //добавляем пользователя в БД _cc.Add(c); //сохраняем изменения в БД await _cc.SaveChangesAsync(); //Properties.Resources.Remember = true; await Authenticate(c.Login);//аутентификация ViewBag.message = "Пользователь " + c.Login + " успешно зарегистрирован!"; return(RedirectToAction("Index", "Buy")); } else { ModelState.AddModelError("", "Некорректные логин или пароль, либо введёные вами телефон или e-mail уже существуют"); } } return(View(c)); }
public async Task <IActionResult> Create([Bind("Id,Name,CourseDescription")] Classes classes) { if (ModelState.IsValid) { _context.Add(classes); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(classes)); }
public async Task <IActionResult> Create([Bind("Id,Name,Email")] GroupMembers groupMembers) { if (ModelState.IsValid) { _context.Add(groupMembers); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(groupMembers)); }
public async Task <IActionResult> Create([Bind("Id,Name,Email,ClassId")] Teachers teacher) { if (ModelState.IsValid) { _context.Add(teacher); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ClassId"] = new SelectList(_context.Classes, "Id", "Id", teacher.ClassId); return(View(teacher)); }
static void Main(string[] args) { using (var db = new ClassContext()) { db.Add(new Instructor { InstructorId = "A01968215", Name = "Phil Weier" }); //db.Add(new Class { ClassId = 1, Instructor = new Instructor { InstructorId = "A01968415", Name = "Phil Weier" }, InstructorId = "3", Title = "teacher" }); db.SaveChanges(); foreach (Instructor instructor in db.Instructors) { Console.WriteLine(instructor.InstructorId + ": " + instructor.Name); } } }