public bool Update(int TrainId, TrainDetail tdl) { var update = from td in db.TrainDetails where td.TRAIN_ID == TrainId select td; if (update.Any()) { update.Single().TRAIN_FROM_TO = tdl.TRAIN_FROM_TO; update.Single().TRAIN_NAME = tdl.TRAIN_NAME; update.Single().TRAIN_NUM_COM_1AC = tdl.TRAIN_NUM_COM_1AC; update.Single().TRAIN_NUM_COM_2AC = tdl.TRAIN_NUM_COM_2AC; update.Single().TRAIN_NUM_COM_3AC = tdl.TRAIN_NUM_COM_3AC; update.Single().TRAIN_NUM_COM_SLEEPER = tdl.TRAIN_NUM_COM_SLEEPER; update.Single().TRAIN_NUM_COM_GEN = tdl.TRAIN_NUM_COM_GEN; update.Single().TRAIN_TOTAL_COM = tdl.TRAIN_TOTAL_COM; update.Single().TRAIN_TYPE = tdl.TRAIN_TYPE; try { db.SubmitChanges(); return true; } catch (Exception ex) { return false; } } return false; }
public String Insert(TrainDetail td) { db.TrainDetails.InsertOnSubmit(td); try { db.SubmitChanges(); return Constants.INSERT_SUCCESS; } catch (Exception ex) { return ex.Message; } }
public static int getMaxNumberOfClass(string Compartment, TrainDetail tdd) { switch (Compartment) { case Constants.AC1: return Constants.NUMER_OF_1AC_COM * tdd.TRAIN_NUM_COM_1AC; case Constants.AC2: return Constants.NUMER_OF_2AC_COM * tdd.TRAIN_NUM_COM_2AC; case Constants.AC3: return Constants.NUMER_OF_3AC_COM * tdd.TRAIN_NUM_COM_3AC; case Constants.SLP: return Constants.NUMER_OF_SLEEP_COM * tdd.TRAIN_NUM_COM_SLEEPER; case Constants.GNR: return Constants.NUMER_OF_GEN_COM * tdd.TRAIN_NUM_COM_GEN; default: return 0; } }
public ActionResult Edit(FormCollection Form) { int TrainId = int.Parse(Form["TrainID"].ToString()); TrainDetail td = new TrainDetail(); td.TRAIN_NAME = Form["Name"]; td.TRAIN_TOTAL_COM = int.Parse(Form["TotalCom"]); td.TRAIN_NUM_COM_1AC = int.Parse(Form["1AC"]); td.TRAIN_NUM_COM_2AC = int.Parse(Form["2AC"]); td.TRAIN_NUM_COM_3AC = int.Parse(Form["3AC"]); td.TRAIN_NUM_COM_SLEEPER = int.Parse(Form["Sleeper"]); td.TRAIN_NUM_COM_GEN = int.Parse(Form["General"]); td.TRAIN_FROM_TO = Form["From"] + "-" + Form["To"]; td.TRAIN_TYPE = int.Parse(Form["TrainType"]); if (tm.Update(TrainId, td)) { return RedirectToAction("Index"); } else { ViewData["Error"] = "Can not update this train"; return View(); } }
public ActionResult Create(FormCollection Form) { string result; try { TrainDetail td = new TrainDetail(); td.TRAIN_NAME = Form["Name"]; td.TRAIN_TOTAL_COM = int.Parse(Form["TotalCom"]); td.TRAIN_NUM_COM_1AC = int.Parse(Form["1AC"]); td.TRAIN_NUM_COM_2AC = int.Parse(Form["2AC"]); td.TRAIN_NUM_COM_3AC = int.Parse(Form["3AC"]); td.TRAIN_NUM_COM_SLEEPER = int.Parse(Form["Sleeper"]); td.TRAIN_NUM_COM_GEN = int.Parse(Form["General"]); td.TRAIN_FROM_TO = Form["From"] + "-" + Form["To"]; td.TRAIN_TYPE = int.Parse(Form["TrainType"]); result = tm.Insert(td); } catch (Exception ex) { result = ex.Message; } return RedirectToAction("Add", new { msg = result}); }
partial void DeleteTrainDetail(TrainDetail instance);
partial void UpdateTrainDetail(TrainDetail instance);
partial void InsertTrainDetail(TrainDetail instance);
private void detach_TrainDetails(TrainDetail entity) { this.SendPropertyChanging(); entity.TrainTypeDetail = null; }