public List <MechanicViewModel> getAllMechanics() { List <MechanicViewModel> list = new List <MechanicViewModel>(); try { var entities = _dbContext.Mechanics.OrderBy(c => c.CreatedDate).ToList(); if (entities != null) { foreach (var item in entities) { //// TODO: automapper mapping var config = new MapperConfiguration(cfg => cfg.CreateMap <Models.Mechanic, MechanicViewModel>()); var mapper = new Mapper(config); MechanicViewModel mechanic = mapper.Map <MechanicViewModel>(item); list.Add(mechanic); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(list); }
public ActionResult Index(MechanicViewModel mechanic) { // Exception Handling try { if (ModelState.IsValid) { string add = _mechanicManager.CreateMechanic(mechanic); Log.Info("Mechanic created Successffuly"); return(RedirectToAction("Index")); } } // Catch the Exception catch (Exception ex) { Log.Error(ex.ToString()); ModelState.AddModelError("", "Error in mechanic created"); } var mechanics = new MechanicViewModel() { mechaniclist = _mechanicManager.GetAllMechanic() }; return(View(mechanics)); }
private void ReloadMechanics() { if (this.AssignedSchedule != null && this.AssignedSchedule.Count > 0) { foreach (var item in this.AssignedSchedule) { MechanicViewModel mechanic = MechanicList.Where(m => m.Id == item.MechanicId).FirstOrDefault(); if (mechanic != null) { SelectedMechanicList.Add((MechanicViewModel)mechanic); } } foreach (var item in SelectedMechanicList) { MechanicList.Remove((MechanicViewModel)item); } RebindListboxes(); } else { this.AssignedSchedule = new List <SPKScheduleViewModel>(); } RebindListboxes(); }
public MechanicViewModel GetMechanic(int?Id) { int id = (int)Id; MechanicViewModel MechanicsEntities = _dbContext.Where(s => s.MechanicId == id).First(); return(MechanicsEntities); }
public string DeleteMechanic(int?Id) { int id = (int)Id; MechanicViewModel MechanicEntitie = _dbContext.Where(s => s.MechanicId == id).First(); _dbContext.Remove(MechanicEntitie); return("Deleted"); }
public string UpdateMechanic(MechanicViewModel viewModel) { var Mechanic = mapper.Map <MechanicViewModel, Mechanic>(viewModel); Mechanic.UpdatedDate = DateTime.Now; var result = _MechanicRepository.UpdateMechanic(Mechanic); return(result); }
public string UpdateMechanic(MechanicViewModel model) { if (model != null) { _dbContext.Add(model); return("Mechanic updated"); } return("Model is null"); }
public void DeleteMechanic(MechanicViewModel mechanic, int userId) { Mechanic entity = _mechanicRepository.GetById(mechanic.Id); entity.Status = (int)DbConstant.DefaultDataStatus.Deleted; entity.ModifyDate = DateTime.Now; entity.ModifyUserId = userId; _mechanicRepository.Update(entity); _unitOfWork.SaveChanges(); }
public ActionResult EditMechanic(MechanicViewModel viewModel) { if (ModelState.IsValid) { var result = _MechanicManager.UpdateMechanic(viewModel); return(RedirectToAction("ListMechanic")); } return(View(viewModel)); }
public ActionResult Edit(MechanicViewModel mechanic) { if (ModelState.IsValid) { string update = _mechanicManager.UpdateMechanic(mechanic); return(RedirectToAction("Index")); } ViewBag.DeptId = new SelectList(_departmentManager.GetAllDepartment(), "DeptId", "Department1"); return(View(mechanic)); }
public ActionResult Index() { var mechanic = new MechanicViewModel() { mechaniclist = _mechanicManager.GetAllMechanic() }; Log.Info("Mechanic listing Successffuly"); return(View(mechanic)); }
private void btnSearch_Click(object sender, EventArgs e) { if (!bgwMain.IsBusy) { MethodBase.GetCurrentMethod().Info("Fecthing Mechanic data..."); _selectedMechanic = null; FormHelpers.CurrentMainForm.UpdateStatusInformation("Memuat data Mechanic...", false); bgwMain.RunWorkerAsync(); } }
public void UpdateMechanic(MechanicViewModel mechanic, int userId) { Mechanic entity = _mechanicRepository.GetById(mechanic.Id); Map(mechanic, entity); entity.ModifyDate = DateTime.Now; entity.ModifyUserId = userId; _mechanicRepository.Update(entity); _unitOfWork.SaveChanges(); }
public void InsertMechanic(MechanicViewModel mechanic, int userId) { Mechanic entity = new Mechanic(); Map(mechanic, entity); entity.CreateUserId = entity.ModifyUserId = userId; entity.CreateDate = entity.ModifyDate = DateTime.Now; entity.Status = (int)DbConstant.DefaultDataStatus.Active; _mechanicRepository.Add(entity); _unitOfWork.SaveChanges(); }
public string CreateMechanic(MechanicViewModel model) { if (model != null) { Mechanic entity = Mapper.Map <MechanicViewModel, Mechanic>(model); _dbContext.Mechanics.Add(entity); _dbContext.SaveChanges(); return("Mechanic added"); } return("Model is null"); }
private void bgwMain_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Result is Exception) { this.ShowError("Proses memuat data gagal!"); } if (MechanicListData.Count > 0) { gvMechanic.FocusedRowHandle = 0; _selectedMechanic = gvMechanic.GetRow(0) as MechanicViewModel; } FormHelpers.CurrentMainForm.UpdateStatusInformation("Memuat data Mechanic selesai", true); }
public string UpdateMechanic(MechanicViewModel model) { if (model != null) { Mechanic entity = _dbContext.Mechanics.Find(model.MechanicId); Mapper.Map(model, entity); _dbContext.Entry(entity).State = EntityState.Modified; _dbContext.SaveChanges(); return("Mechanic updated"); } return("Model is null"); }
public HttpResponseMessage updateMechanicDetails([FromBody] MechanicViewModel model) { bool result = _mechanicManager.updateMechanicDetails(model); if (result) { return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotModified)); } }
public HttpResponseMessage getMechanicByExID(string exID) { MechanicViewModel result = _mechanicManager.getMechanicByExID(exID); if (result != null) { return(Request.CreateResponse(HttpStatusCode.OK, result)); } else { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MechanicViewModel mechanic = _mechanicManager.GetMechanic(id); if (mechanic == null) { return(HttpNotFound()); } return(View(mechanic)); }
// GET: Customers/Details/5 public ActionResult Details(int id) { //if (id == null) //{ // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //} MechanicViewModel mechanic = _mechanicManager.GetMechanic(id); if (mechanic == null) { return(HttpNotFound()); } return(View(mechanic)); }
// GET: Customers/Edit/5 public ActionResult Edit(int id) { //if (id == null) //{ // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //} MechanicViewModel mechanic = _mechanicManager.GetMechanic(id); if (mechanic == null) { return(HttpNotFound()); } ViewBag.DeptId = new SelectList(_departmentManager.GetAllDepartment(), "DeptId", "Department1"); return(View(mechanic)); }
public string CreateMechanic(MechanicViewModel model) { if (model != null) { int Mechanic = _dbContext.Where(a => a.MechanicId == model.MechanicId).Count(); if (Mechanic > 0) { return("Exist"); } _dbContext.Add(model); return("Mechanic added"); } return("Model is null"); }
public static MechanicViewModel MapToViewModel(this Mechanic mechanic) { var model = new MechanicViewModel(); model.Id = mechanic.Id; model.UserName = mechanic.UserName; model.Password = mechanic.Password; model.Email = mechanic.Email; model.CompanyName = mechanic.CompanyName; model.City = mechanic.City; model.Country = mechanic.Country; model.Address = mechanic.Address; model.PostalCode = mechanic.PostalCode; return(model); }
public ActionResult Edit(MechanicViewModel mechanic) { // Exception handling try { if (ModelState.IsValid) { string update = _mechanicManager.UpdateMechanic(mechanic); Log.Info("Mechanic update Successffuly"); return(RedirectToAction("Index")); } } // Catch the exception catch (Exception ex) { Log.Error(ex.ToString()); ModelState.AddModelError("", "Error in mechanic updating"); } return(View(mechanic)); }
public bool updateMechanicDetails(MechanicViewModel model) { try { Mechanic mechanic = _dbContext.Mechanics.Where(s => model.ExternalID.Equals(s.ExternalID)).FirstOrDefault(); if (mechanic.Name != null) { var config = new MapperConfiguration(cfg => cfg.CreateMap <MechanicViewModel, Mechanic>()); var mapper = new Mapper(config); mapper.Map <MechanicViewModel, Mechanic>(model, mechanic); _dbContext.SaveChanges(); return(true); } } catch (Exception ex) { //return false; } return(false); }
public bool registerMechanic(MechanicViewModel model) { try { var config = new MapperConfiguration(cfg => cfg.CreateMap <MechanicViewModel, Models.Mechanic>()); var mapper = new Mapper(config); Models.Mechanic mechanic = mapper.Map <Models.Mechanic>(model); mechanic.ID = 0; mechanic.ExternalID = Guid.NewGuid(); mechanic.CreatedDate = DateTime.Now; mechanic.CreatedBy = 1; mechanic.IsActive = true; _dbContext.Mechanics.Add(mechanic); _dbContext.SaveChanges(); } catch (System.Data.Entity.Infrastructure.DbUpdateConcurrencyException ex) { Console.WriteLine(ex.InnerException); } catch (System.Data.Entity.Core.EntityCommandCompilationException ex) { Console.WriteLine(ex.InnerException); } catch (System.Data.Entity.Core.UpdateException ex) { Console.WriteLine(ex.InnerException); } catch (System.Data.Entity.Infrastructure.DbUpdateException ex) //DbContext { Console.WriteLine(ex.InnerException); } catch (Exception ex) { return(false); } return(true); }
public MechanicViewModel getMechanicByExID(string exID) { MechanicViewModel mechanic = new MechanicViewModel(); try { Models.Mechanic Mmechanic = _dbContext.Mechanics.Where(s => exID.Equals(s.ExternalID.ToString())).FirstOrDefault(); if (Mmechanic.Name != null) { //// TODO: automapper mapping var config = new MapperConfiguration(cfg => cfg.CreateMap <Models.Mechanic, MechanicViewModel>()); var mapper = new Mapper(config); mechanic = mapper.Map <MechanicViewModel>(Mmechanic); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(mechanic); }
public MechanicViewModel GetMechanic(int Id) { MechanicViewModel mechanicsEntities = Mapper.Map <MechanicViewModel>(_dbContext.Mechanics.Find(Id)); return(mechanicsEntities); }
public bool updateMechanicDetails(MechanicViewModel model) { return(_mechanicRepository.updateMechanicDetails(model)); }