public async Task <ActionResult> DeleteConfirmed(int id) { MottorModel model = await _dbContext.MottoModels.FindAsync(id); _dbContext.MottoModels.Remove(model); await _dbContext.SaveChangesAsync(); Success("Model Deleted Successfully", true); return(Json(new { success = true })); }
public static MottorModelViewModel MottoEntityToViewModel(MottorModel model) { var entity = new MottorModelViewModel() { Id = model.Id, Name = model.Name, Total = model.Total, Date = model.Date, Make = model.Make }; return(entity); }
public static MottorModel ViewModelToMottoEntity(MottorModelViewModel model) { var entity = new MottorModel() { Id = model.Id >= 1 ? model.Id : 0, Name = model.Name.ToUpper(), Date = DateTime.UtcNow, Make = model.Make.ToUpper(), Total = model.Total }; return(entity); }
public async Task <ActionResult> Edit(MottorModelViewModel model) { if (ModelState.IsValid) { MottorModel modelDriver = MottoModelFactory.ViewModelToMottoEntity(model); _dbContext.Entry(modelDriver).State = EntityState.Modified; await _dbContext.SaveChangesAsync(); Success("Model Updated Successfully", true); return(Json(new { success = true })); } return(PartialView("_Edit", model)); }
public async Task <ActionResult> Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MottorModel motto = await _dbContext.MottoModels.FindAsync(id); if (motto == null) { return(HttpNotFound()); } MottorModelViewModel mottoModelViewModel = MottoModelFactory.MottoEntityToViewModel(motto); return(PartialView("_Delete", mottoModelViewModel)); }
public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MottorModel driver = await _dbContext.MottoModels.FindAsync(id); if (driver == null) { return(HttpNotFound()); } MottorModelViewModel driverViewModel = MottoModelFactory.MottoEntityToViewModel(driver); return(PartialView("_Edit", driverViewModel)); }