public ActionResult Create() { var model = new MottorViewModel(); setModeList(model); return(PartialView("_Create", model)); }
public static bool isPlateNumberAlreadyExisting(Mottor model, MottorViewModel viewModel) { if (model.PlateNumber.Trim() == viewModel.PlateNumber.Trim()) { return(true); } return(false); }
// Private function private MottorViewModel setModeList(MottorViewModel model) { var departments = _context.Departments.ToList(); var models = _context.MottoModels.ToList(); var vehicles = _context.Vehicles.ToList(); model.SelectLists(departments, models, vehicles); return(model); }
public static MottorViewModel MottoEntityToViewModelFOrEdit(Mottor model) { var motto = new MottorViewModel() { Id = model.Id, MottorModelId = model.MottorModelId, PlateNumber = model.PlateNumber, IsAvailable = model.IsAvailable, VehicleId = model.VehicleId, DepartmentId = model.DepartmentId, }; return(motto); }
public async Task <ActionResult> Edit(MottorViewModel model) { if (ModelState.IsValid) { Mottor motto = MottorFactory.ViewModelToMottoEntity(model); _context.Entry(motto).State = EntityState.Modified; await _context.SaveChangesAsync(); Success("Motto with the plate number : " + motto.PlateNumber + " Updated Successfully", true); return(Json(new { success = true })); } return(PartialView("_Edit", model)); }
public static Mottor ViewModelToMottoEntity(MottorViewModel model) { var entity = new Mottor() { Id = model.Id >= 1 ? model.Id : 0, DepartmentId = model.DepartmentId, VehicleId = model.VehicleId, MottorModelId = model.MottorModelId, PlateNumber = model.PlateNumber.ToUpper(), IsAvailable = model.IsAvailable, DateCreated = DateTime.UtcNow // VehicleMovements = }; return(entity); }
public async Task <ActionResult> Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Mottor motto = await _context.Mottors.FindAsync(id); if (motto == null) { return(HttpNotFound()); } MottorViewModel mottoViewModel = MottorFactory.MottoEntityToViewModelFOrEdit(motto); return(PartialView("_Delete", mottoViewModel)); }
public async Task <ActionResult> Create(MottorViewModel model) { //Check the validity of the model if (ModelState.IsValid) { try { bool isPlateNumberExist = false; // search for plate number var allMottors = _context.Mottors .ToList() .FirstOrDefault(x => x.PlateNumber.ToLower().Trim() == model.PlateNumber.ToLower().Trim()); if (allMottors != null) { isPlateNumberExist = MottorFactory.isPlateNumberAlreadyExisting(allMottors, model); } //ValidateRequest plate number //redirect to index if (isPlateNumberExist == true) { Warning("Mottor with plate number " + model.PlateNumber + " is already existing ", true); return(Json(new { success = true })); } var motto = MottorFactory.ViewModelToMottoEntity(model); _context.Mottors.Add(motto); var i = await _context.SaveChangesAsync(); } catch (Exception ex) { Danger(ex.Message, true); return(Json(new { success = true })); } // call an instance of Driver Class Success("Creted Successfully", true); return(Json(new { success = true })); } return(PartialView("_Create", model)); }
public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //find model Mottor model = await _context.Mottors.FindAsync(id); if (model == null) { return(HttpNotFound()); } //validate all by including all the vehicle var singleOrDefault = _context.Mottors .Include(x => x.Department) .Include(x => x.Vehicle) .Include(x => x.MottorModel) .FirstOrDefault(x => x.Id == model.Id); // check if such mottor cannot be found. if (singleOrDefault == null) { Warning("Cannot find such mottor", true); return(Json(new { success = true })); } model = singleOrDefault; MottorViewModel mottoViewModel = MottorFactory.MottoEntityToViewModel(model); return(PartialView("_Details", mottoViewModel)); }
public static MottorViewModel MottoEntityToViewModel(Mottor model) { var entity = new MottorViewModel(model); return(entity); }