public async Task <IActionResult> Login(LoginViewModel l) { if (ModelState.IsValid) { //Проверка данных в БД Customer customer = await _cc.Customer.FirstOrDefaultAsync (c => c.Login == l.Login && c.Password == l.Password); if (customer != null) { //if (l.RememberMe) Properties.Resources.Remember = true; //else Properties.Resources.Remember = false; await Authenticate(l.Login); //аутентификация customer.RememberMe = l.RememberMe; _cc.Update(customer); await _cc.SaveChangesAsync(); return(RedirectToAction("Index", "Buy")); } else { ModelState.AddModelError("", "Некорректные логин или пароль"); } } return(View(l)); }
public async Task <ActionResult <AccionesItem> > PostAciones(AccionesItem item) { _context.Acciones.Add(item); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetAcciones), new { cod_Accion = item.cod_Accion }, item)); }
public async Task <ActionResult <DocenteItem> > PostDocente(DocenteItem docente) { _context.DocenteItems.Add(docente); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetDocentes), new { identificacion = docente.Identificacion }, docente)); }
public async Task <ActionResult <TipoActividad> > PostTipoActividad(TipoActividad item) { _context.TipoActividades.Add(item); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetTipoActividades), new { cod_TipoActividad = item.cod_TipoActividad }, item)); }
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,CourseDescription")] Classes classes) { if (ModelState.IsValid) { _context.Add(classes); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(classes)); }
public async Task <ActionResult> Create([Bind(Include = "Id,Nome,Turno,Ano")] Turma turma) { if (ModelState.IsValid) { db.Turmas.Add(turma); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(turma)); }
public async Task <ActionResult> Create([Bind(Include = "ProfessorId,Nome")] Professor professor) { if (ModelState.IsValid) { db.Professores.Add(professor); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(professor)); }
public async Task <ActionResult <PlanAcciones> > PostPlan(PlanAcciones plan) { if (plan.ActividadAsignada != null) { plan.ActividadId = plan.ActividadAsignada.idActividad; plan.ActividadAsignada = null; } _context.Planes.Add(plan); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetPlan), new { id = plan.IdPlanAcciones }, plan)); }
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)); }
public async Task <ActionResult <ActividadAsignada> > PostAsignarActividad(ActividadAsignada item) { if (item.DocenteItem != null) { item.DocenteItemId = item.DocenteItem.identificacion; item.DocenteItem = null; } _context.ActividadesAsignadas.Add(item); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetActividadAsignadasItem), new { id = item.idActividad }, item)); }
public async Task <ActionResult> Create([Bind(Include = "AlunoId,Nome,TurmaId")] Aluno aluno) { if (ModelState.IsValid) { db.Alunos.Add(aluno); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.TurmaId = new SelectList(db.Turmas, "Id", "Nome", aluno.TurmaId); return(View(aluno)); }
public async Task <ActionResult> Create([Bind(Include = "DisciplinaId,Nome,ProfessorId")] Disciplina disciplina) { if (ModelState.IsValid) { db.Disciplinas.Add(disciplina); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.ProfessorId = new SelectList(db.Professores, "ProfessorId", "Nome", disciplina.ProfessorId); return(View(disciplina)); }
public async Task <ActionResult <DocenteItem> > PostDocente(DocenteItem item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } /**var docenteItem = await _context.Docentes.FindAsync(identificacion); * if (docenteItem != null) * { * return BadRequest(); * }*/ _context.Docentes.Add(item); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetDocentes), new { identificacion = item.identificacion }, item)); }
public async Task <IActionResult> EditProfile(Customer c) { if (!ModelState.IsValid) { Customer customer = await _db.Customer.FirstOrDefaultAsync(cu => cu.Login == User.Identity.Name); Customer check_customer_login = await _db.Customer.FirstOrDefaultAsync(cus => cus.Login == c.Login); Customer check_customer_email = await _db.Customer.FirstOrDefaultAsync(cus => cus.Email == c.Email); Customer check_customer_phone = await _db.Customer.FirstOrDefaultAsync(cus => cus.Phone == c.Phone); if (check_customer_login == null || check_customer_email == null || check_customer_phone == null) { customer.FIO = c.FIO; customer.Gender = c.Gender; customer.DateOfBirth = c.DateOfBirth; customer.Email = c.Email; customer.Phone = c.Phone; customer.Login = c.Login; _db.Customer.Update(customer); await _db.SaveChangesAsync(); await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); var claims = new List <Claim> { new Claim(ClaimsIdentity.DefaultNameClaimType, customer.Login) }; // создаем объект ClaimsIdentity ClaimsIdentity id = new ClaimsIdentity(claims, "ApplicationCookie", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType); //установка идентификационных куки await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(id)); return(RedirectToAction("MyProfile")); } else { ModelState.AddModelError("", "Некорректные логин, e-mail или номер телефона либо аккаунт с такими данными уже существует"); } } return(View(c)); }
/// <inheritdoc /> public async Task <bool> InsertRecordAsync <T>(T dataModel) { if (dataModel is Group group) { // Add new record to the database await _classContext.Groups.AddAsync(group); // Save changes return(await _classContext.SaveChangesAsync() > 0); } // Add new person to the database Person person = dataModel as Person; // Add new person record to the database await _classContext.Persons.AddAsync(person !); return(await _classContext.SaveChangesAsync() > 0); }
public async Task <IActionResult> Index(int?category, string name, string typeSort = "None", string attributeSort = "None") { //if (User.Identity.IsAuthenticated) //{ // Customer c = await _db.Customer.FirstOrDefaultAsync(cu => cu.Login == User.Identity.Name); // if (!c.RememberMe) // { // await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); // } //} foreach (var p in _db.Product) { if (p.NameImage != null) { var bytes = System.IO.File.ReadAllBytes(p.NameImage); p.Image = bytes; } } await _db.SaveChangesAsync(); IQueryable <Product> products = _db.Product.Include(c => c.Category); if (category != null && category != 0) { products = products.Where(p => p.Id_category == category); } switch (attributeSort + typeSort) { case "NameAsc": products = products.OrderBy(s => s.Name); break; case "NameDesc": products = products.OrderByDescending(s => s.Name); break; case "PriceAsc": products = products.OrderBy(s => s.Price); break; case "PriceDesc": products = products.OrderByDescending(s => s.Price); break; } IndexViewModel viewModel = new IndexViewModel { SortViewModel = new SortViewModel(typeSort, attributeSort), FilterViewModel = new FilterViewModel(_db.Category.ToList(), category, name), Products = products }; return(View(viewModel)); }