public async Task <IActionResult> Delete(CourseDeleteInputModel inputModel) { await courseService.DeleteCourseAsync(inputModel); TempData["ConfirmationMessage"] = "Il corso è stato eliminato ma potrebbe continuare a comparire negli elenchi per un breve periodo, finché la cache non viene aggiornata."; return(RedirectToAction(nameof(Index))); }
public async Task DeleteCourseAsync(CourseDeleteInputModel inputModel) { int affectedRows = await this.db.CommandAsync($"UPDATE Courses SET Status={nameof(CourseStatus.Deleted)} WHERE Id={inputModel.Id} AND Status<>{nameof(CourseStatus.Deleted)}"); if (affectedRows == 0) { throw new CourseNotFoundException(inputModel.Id); } }
public async Task DeleteCourseAsync(CourseDeleteInputModel inputModel) { Course course = await dbContext.Courses.FindAsync(inputModel.Id); if (course == null) { throw new CourseNotFoundException(inputModel.Id); } course.ChangeStatus(CourseStatus.Deleted); await dbContext.SaveChangesAsync(); }
public ActionResult Delete(CourseDeleteInputModel courseDeleteInputModel) { if (courseDeleteInputModel == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Course course = this.courseService.GetById(courseDeleteInputModel.CourseId); if (course == null) { return(this.HttpNotFound()); } this.courseService.Delete(course); return(this.RedirectToAction("Index", "Home")); }
public async Task DeleteCourseAsync(CourseDeleteInputModel inputModel) { await courseService.DeleteCourseAsync(inputModel); memoryCache.Remove($"Course{inputModel.Id}"); }