public ActionResult EditHistorico(AddProdutoView view) { var produto = _context.Produto.First(a => a.Id_produto == produtoView.ProductId); var pesquisa = listaProduto.Exists(x => x.Produto.Id_produto == produtoView.ProductId); var pesquisaPreco = _context.Historico.Where(x => x.Id_historico == view.Id_historico).FirstOrDefault(); if (pesquisa) { listaProduto.RemoveAll(x => x.Produto_Id_produto == produtoView.ProductId); } if (produtoView.Quantity > produto.Estoque_atual) { return(RedirectToAction("ErroEditProd", new { produto = produto.Nome, quantidade = produto.Estoque_atual })); } CotacaoProduto vendaProduto = new CotacaoProduto(); vendaProduto.Valor_unitario = Convert.ToString(pesquisaPreco.Valor); vendaProduto.Produto = produto; vendaProduto.Produto_Id_produto = produto.Id_produto; vendaProduto.Quantidade = Convert.ToInt32(produtoView.Quantity); vendaProduto.Valor = decimal.Multiply(Convert.ToDecimal(pesquisaPreco.Valor), Convert.ToDecimal(produtoView.Quantity)); produto.Estoque_atual = produto.Estoque_atual - Convert.ToInt32(produtoView.Quantity); _context.Produto.Update(produto); _context.SaveChanges(); listaProduto.Add(vendaProduto); return(RedirectToAction("Edit", new { id = idEdit })); }
public IActionResult Edit(HomeTask homeTaskParameter) { if (!ModelState.IsValid) { ViewData["Action"] = "Edit"; return(View(homeTaskParameter)); } var homeTask = this.context.HomeTask.Include(c => c.Course).SingleOrDefault(h => h.Id == homeTaskParameter.Id); homeTask.Title = homeTaskParameter.Title; homeTask.Number = homeTaskParameter.Number; homeTask.Description = homeTaskParameter.Description; homeTask.Date = homeTaskParameter.Date; var routeValueDictionary = new RouteValueDictionary(); this.context.Update(homeTask); context.SaveChanges(); routeValueDictionary.Add("id", homeTask.Course.Id); return(RedirectToAction("HomeTasks", "HomeTask", routeValueDictionary)); }
public ActionResult Create([Bind(Include = "OgrenciID,Ad,Soyad,DogumTarihi,EPosta")] Ogrenci ogrenci) { if (ModelState.IsValid) { db.Ogrenciler.Add(ogrenci); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ogrenci)); }
private async Task UpdateUserAndUserRole(UniUser user, string newRoleName) { var res1 = await UserManager.RemoveFromRoleAsync(user.Id, user.Role); var res2 = await UserManager.AddToRoleAsync(user.Id, newRoleName); user.Role = newRoleName; var oldUser = db.Users.Find(user.Id); db.Entry(oldUser).CurrentValues.SetValues(user); db.SaveChanges(); }
public ActionResult Create(CourseCreationViewModel courseCreationViewModel) { if (ModelState.IsValid) { var course = courseCreationViewModel.Course; course.Teacher = db.Users.Find(courseCreationViewModel.SelectedTeacherId); db.Courses.Add(course); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(courseCreationViewModel)); }
public IActionResult AssignStudents(CourseStudentAssignment assignmentViewModel) { this.SetStudentsToCourse(assignmentViewModel.Id, assignmentViewModel.Students.Where(p => p.IsAssigned).Select(student => student.StudentId)); context.StudentCourse.RemoveRange(); context.SaveChanges(); return(RedirectToAction("Courses")); }
public ActionResult SaveSemester(Semester semester) { try { if (ModelState.IsValid) { db.Semesters.Add(semester); db.SaveChanges(); return(RedirectToAction("SemesterIndex")); } return(RedirectToAction("SaveSemester")); } catch (Exception ex) { Console.WriteLine(ex); throw; } }
// Delete book public void delete(string strBookID) { using (var context = new UniContext()) { var book = context.Books.Where(x => x.BookID.ToString().Equals(strBookID)).Single(); context.Books.Remove(book); context.SaveChanges(); } }
// Edit book public void Edit(string strBookID) { using (var context = new UniContext()) { var book = context.Books.Where(x => x.BookID.ToString().Equals(strBookID)).Single(); book.BookName = "BookEdit"; context.SaveChanges(); } }
public async Task <ActionResult> AddGrade(AddGradeViewModel addGradeViewModel) { if (ModelState.IsValid) { Grade grade = new Grade(); grade.Course = db.Courses.Find(addGradeViewModel.CourseId); grade.GradingTeacher = grade.Course.Teacher; grade.Mark = addGradeViewModel.Mark; grade.Student = db.Users.Find(addGradeViewModel.StudentId); grade.CreationDate = DateTime.Now; db.Grades.Add(grade); db.SaveChanges(); return(RedirectToAction("EditGrades", new { courseId = addGradeViewModel.CourseId, studentId = addGradeViewModel.StudentId })); } return(View(addGradeViewModel)); }
public StudentController(UniContext context) // dependency injection of SudentRepo class instance { this.context = context; if (context.Students.Count() == 0) { // Create a new TodoItem if collection is empty, // which means you can't delete all TodoItems. foreach (var item in studs) { context.Students.Add(item); } context.SaveChanges(); } }
// Add new book public void Add() { using (var context = new UniContext()) { var book = new Book { BookID = "BK00000001", BookName = "FullStack React", Tags = "React", Publisher = "FullStack.io", Authors = "FullStack.io", Pages = 678, Size = 12.3 }; context.Books.Add(book); context.SaveChanges(); } }
public ActionResult AddDepartment([Bind(Include = "Id,Code,Name")] Department department) { if (ModelState.IsValid) { if (!db.Departments.Any(d => d.Code == department.Code)) { db.Departments.Add(department); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("AddDepartment")); } } return(View()); }