public ActionResult CreateEdit(TypeBusViewModel model) { try { if (ModelState.IsValid) { if (TypeBusDataAccess.Update(model)) { return(Json(new { success = true, message = "Success" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = TypeBusDataAccess.Message }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { success = false, message = "Lengkapi isi form nya" }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(new { success = false, ex.Message }, JsonRequestBehavior.AllowGet)); } }
public static TypeBusViewModel GetById(int id) { TypeBusViewModel result = new TypeBusViewModel(); using (var db = new FleetManagementContext()) { result = (from tb in db.MstTypeBus join mb in db.MstMerkBus on tb.MerkId equals mb.MerkId where tb.Id == id select new TypeBusViewModel { Id = tb.Id, MerkId = tb.MerkId, MerkName = mb.Description, TypeId = tb.TypeId, Description = tb.Description, IsActive = tb.IsActive, CreatedBy = tb.CreatedBy, Created = tb.Created, ModifiedBy = tb.ModifiedBy, Modified = tb.Modified }).FirstOrDefault(); } return(result); }
public static bool Update(TypeBusViewModel model) { bool result = true; try { using (var db = new FleetManagementContext()) { if (model.Id == 0) { MstTypeBu typebus = new MstTypeBu(); typebus.MerkId = model.MerkId; typebus.TypeId = model.TypeId; typebus.Description = model.Description; typebus.IsActive = model.IsActive; typebus.CreatedBy = model.CreatedBy; typebus.Created = model.Created; typebus.ModifiedBy = model.ModifiedBy; typebus.Modified = model.Modified; db.MstTypeBus.Add(typebus); db.SaveChanges(); } else { MstTypeBu typebus = db.MstTypeBus.Where(o => o.Id == model.Id).FirstOrDefault(); if (typebus != null) { typebus.MerkId = model.MerkId; typebus.TypeId = model.TypeId; typebus.Description = model.Description; typebus.IsActive = model.IsActive; typebus.CreatedBy = model.CreatedBy; typebus.Created = model.Created; typebus.ModifiedBy = model.ModifiedBy; typebus.Modified = model.Modified; db.SaveChanges(); } } } } catch (Exception ex) { Message = ex.Message; result = false; } return(result); }
public ActionResult Edit(TypeBusViewModel model) { return(CreateEdit(model)); }