public async Task <IActionResult> UpdateVote(int feedback, int vote) { var user = await _context.Users.SingleOrDefaultAsync(u => u.Login == User.Identity.Name); if (user.VotesCounter > 0) { user.VotesCounter--; _context.Update(user); await _context.SaveChangesAsync(); Vote model = new Vote { RatingGiven = vote, UserId = user.Id, FeedbackId = feedback, Time = DateTime.Now, VoteReturned = false }; _context.Votes.Add(model); await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("Id,Name")] Department department) { if (ModelState.IsValid) { _context.Add(department); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(department)); }
public async Task <IActionResult> Create([Bind("ID,EmpName,EmpDept,EmpEmail,EmpPhone")] Class @class) { if (ModelState.IsValid) { _context.Add(@class); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(@class)); }
public async Task <IActionResult> Create(Movie movie) { if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public async Task <IActionResult> Create(Feedback feedback) { if (ModelState.IsValid) { _context.Add(feedback); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["UserId"] = new SelectList(_context.Users, "Id", "Login", feedback.UserId); return(View(feedback)); }
public async Task <IActionResult> Create([Bind("Id,FirstName,Patronymic,LastName,Login,Password,RoleId,VotesCounter")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["RoleId"] = new SelectList(_context.Roles, "Id", "Name", user.RoleId); return(View(user)); }
public async Task <IActionResult> Create(Vote vote) { if (ModelState.IsValid) { _context.Add(vote); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["FeedbackId"] = new SelectList(_context.Feedbacks, "Id", "Name", vote.FeedbackId); ViewData["UserId"] = new SelectList(_context.Users, "Id", "Login", vote.UserId); return(View(vote)); }
public async Task <ActionResult <Employee> > Post(Employee employee) { var result = await _dataContext.AddAsync(employee); await _dataContext.SaveChangesAsync(); if (result != null) { return(Created("employee", result.Entity)); } else { return(BadRequest("Failed to save new Employee")); } }
public async Task <IActionResult> Index(CommentsViewModel vm) { if (ModelState.IsValid) { //Insert vm.Content.CreateAt = DateTime.Now; _context.Add(vm.Content); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } vm.Contents = await _context.Content.OrderByDescending(column => column.CreateAt).ToListAsync(); return(View(vm)); }
public async Task <IActionResult> Registration(RegistrationModel registrationModel) { if (ModelState.IsValid) { User user = await _context.Users.FirstOrDefaultAsync(u => u.Login == registrationModel.Login); if (user == null) { user = new User { Login = registrationModel.Login, Password = registrationModel.Password, FirstName = registrationModel.FirstName, LastName = registrationModel.LastName, Patronymic = registrationModel.Patronymic, VotesCounter = 10 }; Role userRole = await _context.Roles.FirstOrDefaultAsync(r => r.Name == "Default"); if (userRole != null) { user.Role = userRole; } _context.Users.Add(user); await _context.SaveChangesAsync(); await Authenticate(user); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Неправильный логин и(или) пароль"); } } return(View(registrationModel)); }
public async Task InsertAsync(Seller obj) { _context.Add(obj); await _context.SaveChangesAsync(); }