public async Task EditClassAsync(ClassesInputViewModel classes) { var currentClass = this.repositoryClass.All().FirstOrDefault(x => x.Id == classes.Id); if (currentClass != null) { this.repositoryClass.Delete(currentClass); currentClass = new Class { Id = classes.Id, Name = classes.Name, ImageUrl = classes.ImageUrl, Price = classes.Price, CreatedOn = DateTime.UtcNow, IsActive = classes.IsActive, }; if (classes.Discount == null) { currentClass.Discount = 0; } else { currentClass.Discount = classes.Discount; } await this.repositoryClass.AddAsync(currentClass); } await this.repositoryClass.SaveChangesAsync(); }
public async Task <IActionResult> AddClass(ClassesInputViewModel classes) { if (!this.ModelState.IsValid) { return(this.View(classes)); } await this.adminServices.AddNewClassAsync(classes); return(this.Redirect("/AdminPanel/Classes")); }
public async Task <IActionResult> EditClass(int id, ClassesInputViewModel classes) { if (id != classes.Id) { return(this.NotFound()); } if (!this.ModelState.IsValid) { return(this.View(classes)); } await this.adminServices.EditClassAsync(classes); return(this.Redirect("/AdminPanel/Classes")); }
public async Task <IActionResult> DeleteClass(int id, ClassesInputViewModel classes) { if (id != classes.Id) { return(this.NotFound()); } if (!this.ModelState.IsValid) { this.ModelState.AddModelError(string.Empty, "Sorry we cannot delete this Class!"); } await this.adminServices.DeleteClassAsync(classes); return(this.Redirect("/AdminPanel/Classes")); }
public async Task DeleteClassAsync(ClassesInputViewModel classes) { var currentUserClass = await this.repositoryUserClass.All().FirstOrDefaultAsync(x => x.ClassId == classes.Id); if (currentUserClass != null) { this.repositoryUserClass.Delete(currentUserClass); } var currentClass = await this.repositoryClass.All().FirstOrDefaultAsync(x => x.Id == classes.Id); if (currentClass != null) { this.repositoryClass.Delete(currentClass); } await this.repositoryUserClass.SaveChangesAsync(); await this.repositoryClass.SaveChangesAsync(); }
public async Task AddNewClassAsync(ClassesInputViewModel classes) { var newClass = new Class() { Name = classes.Name, ImageUrl = classes.ImageUrl, Price = classes.Price, CreatedOn = DateTime.UtcNow, IsActive = classes.IsActive, }; if (classes.Discount == null) { newClass.Discount = 0; } else { newClass.Discount = classes.Discount; } await this.repositoryClass.AddAsync(newClass); await this.repositoryClass.SaveChangesAsync(); }