public async Task <IActionResult> Edit(int id, [Bind("HomeworkId,HomeworkDescription,DateLimit,difficulty,Label,idmodule")] Homework homwrk) { if (id != homwrk.HomeworkId) { return(RedirectToAction("Error")); } if (ModelState.IsValid) { _context.Update(homwrk); await _context.SaveChangesAsync(); return(RedirectToAction("GetAll")); } return(View(homwrk)); }
public async Task <IActionResult> Edit(int id, [Bind("CategoryId,CategoryName")] Category category) { if (id != category.CategoryId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(category); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(category.CategoryId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async void ToDoListUpdateTest() { DbContextOptions <ToDoDbContext> options = new DbContextOptionsBuilder <ToDoDbContext>() .UseInMemoryDatabase("todoListUpdate") .Options; using (ToDoDbContext context = new ToDoDbContext(options)) { //CREATE //Arrange ToDoList myList = new ToDoList(); myList.Name = "new list"; context.ToDoList.Add(myList); context.SaveChanges(); //READ var list = await context.ToDoList.FirstOrDefaultAsync(t => t.Name == myList.Name); list.Name = "another name"; context.Update(list); context.SaveChanges(); var newList = await context.ToDoList.FirstOrDefaultAsync(t => t.Name == myList.Name); Assert.Equal("another name", newList.Name); } }
public async Task <string> EditApi([FromBody] TimeTable item) { try { var dbItem = _context.TimeTables.FirstOrDefault(m => m.TimeTableId == item.TimeTableId); dbItem.DateDebut = item.DateDebut; dbItem.DateFin = item.DateFin; dbItem.filenamee = item.filenamee; dbItem.filecode = item.filecode; _context.Update(dbItem); await _context.SaveChangesAsync(); return(await Task.Factory.StartNew(() => { return JsonConvert.SerializeObject(dbItem); })); } catch (Exception ex) { var errorMessage = "Failure to PUT. Stack Trace: " + ex.StackTrace; Console.WriteLine(errorMessage); return(await Task.Factory.StartNew(() => { return JsonConvert.SerializeObject(new { msg = errorMessage }); })); } }
public async Task <IActionResult> Edit(int id, [Bind("ToDoId,ToDoName,UserId")] ToDo toDo) { if (id != toDo.ToDoId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(toDo); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ToDoExists(toDo.ToDoId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["UserId"] = new SelectList(_context.Users, "UserId", "UserName", toDo.UserId); return(View(toDo)); }
public async Task <IActionResult> Edit(int id, [Bind("UserId,UserName")] User user) { if (id != user.UserId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.UserId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async void ToDoUpdateTest() { DbContextOptions <ToDoDbContext> options = new DbContextOptionsBuilder <ToDoDbContext>() .UseInMemoryDatabase("todoUpdate") .Options; using (ToDoDbContext context = new ToDoDbContext(options)) { //CREATE //Arrange ToDo taskOne = new ToDo(); taskOne.Name = "Finish homework"; taskOne.Completed = false; context.ToDos.Add(taskOne); context.SaveChanges(); //READ var myTask = await context.ToDos.FirstOrDefaultAsync(t => t.Name == taskOne.Name); myTask.Name = "New Name"; context.Update(myTask); context.SaveChanges(); var newTask = await context.ToDos.FirstOrDefaultAsync(t => t.Name == myTask.Name); Assert.Equal("New Name", newTask.Name); } }
public async Task <IActionResult> Edit(int id, [Bind("ClasssId,NbreEtudiants,Speciality,ClasseName,Level")] Classs clas) { if (id != clas.ClasssId) { return(NotFound()); } if (ModelState.IsValid) { _context.Update(clas); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(clas)); }
public async Task <IActionResult> Edit(int id, [Bind("ModuleId,ModuleName,ModuleCoeif")] Module Modu) { if (id != Modu.ModuleId) { return(NotFound()); } if (ModelState.IsValid) { _context.Update(Modu); await _context.SaveChangesAsync(); return(RedirectToAction("GetAll")); } return(View(Modu)); }
public IActionResult Put(uint id, [FromBody] Activity a) { var db = new ToDoDbContext(); a.Id = id; db.Update(a); db.SaveChanges(); return(Ok()); }
public async Task <IActionResult> Edit(DoList item) { if (ModelState.IsValid) { context.Update(item); await context.SaveChangesAsync(); TempData["Success"] = "The task has been updated."; return(RedirectToAction("Index")); } return(View(item)); }
public string Update(Task model) { var todoContext = new ToDoDbContext();//create instance dbcontext try { todoContext.Update(model); //update model to dataabse todoContext.SaveChanges(); //commit save change } catch (Exception e) { return("Failed when update data"); //return result } return("Successfully update data"); //return result }
public async System.Threading.Tasks.Task <IActionResult> OnPostAsync(Guid id) { var task = _context.Find <Task>(id); if (await TryUpdateModelAsync(task, "Task")) { _context.Update(task); await _context.SaveChangesAsync(); TempData["SuccessMessage"] = $"Task successfully updated"; } return(RedirectToPage("Index")); }
public async Task <IActionResult> Edit(int id, [Bind("id_cours,Description,PublicationDate,Title")] Courss cour) { if (id != cour.id_cours) { return(NotFound()); } if (ModelState.IsValid) { _context.Update(cour); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(cour)); }
public async Task <IActionResult> Edit(int id, [Bind("MarkId,CC,DS,Exam")] Mark Mar) { if (id != Mar.MarkId) { return(NotFound()); } if (ModelState.IsValid) { _context.Update(Mar); await _context.SaveChangesAsync(); return(RedirectToAction("MarkList")); } return(View(Mar)); }
public async Task <IdentityResult> UpdateAsync(User user, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); if (user == null) { throw new ArgumentNullException(nameof(user)); } _context.Update(user); var affectedRows = await _context.SaveChangesAsync(cancellationToken); return(affectedRows > 0 ? IdentityResult.Success : IdentityResult.Failed(new IdentityError() { Description = $"Could not update user {user.Username}." })); }
public async Task <HttpResponseMessage> Put(int id, [FromBody] ToDo todo) { var result = _context.ToDos.FirstOrDefault(t => t.ID == id); if (result != null) { result.Description = todo.Description; result.Done = todo.Done; _context.Update(result); await _context.SaveChangesAsync(); } else { return(new HttpResponseMessage(HttpStatusCode.NotFound)); } return(new HttpResponseMessage(HttpStatusCode.OK)); }
private IActionResult ChangeTaskStatus(Guid id, ETaskStatus current, ETaskStatus next) { var task = _context.Find <Task>(id); if (task != null && task.Status == current) { task.Status = next; _context.Update(task); _context.SaveChanges(); } Tasks = _context.Tasks.ToList(); Request.QueryString = default; return(RedirectToPage("Index")); }
public string UpdateTaskCompleted(int id) { var todoContext = new ToDoDbContext(); //create instance dbcontext try { var dataExist = GetTaskById(id); //find task by id if (dataExist != null) { dataExist.PercentComplete = "100"; //set property todoContext.Update(dataExist); //jpdate model to database todoContext.SaveChanges(); //commit save change } else { return("Failed when process data"); //return result } } catch (Exception e) { return("Failed when update data"); //return result } return("Successfully update data"); //return result }
public string MarkTaskDone(int id) { var todoContext = new ToDoDbContext();//create instance dbcontext try { var dataExist = GetTaskById(id); //get task by id if (dataExist != null) //check if not null { dataExist.Status = "Done"; //set property todoContext.Update(dataExist); //update model to database todoContext.SaveChanges(); //commit save change } else { return("Failed when process data");//return result } } catch (Exception e) { return("Failed when update data"); //return result } return("Successfully update data"); //return result }
public System.Threading.Tasks.Task UpdateTask(Task task) { _context.Update(task); return(_context.SaveChangesAsync()); }
public void Update(Mark mark) { _context.Update(mark); _context.SaveChanges(); }
public Task Update(ToDoList toDoList) { _context.Update(toDoList); return(_context.SaveChangesAsync()); }