public CrewFormStub(Crew dbItem) { Barcode = dbItem.Barcode; NamaCrew = dbItem.Nama; TanggalDaftar = (DateTime) dbItem.Tanggal_Daftar; Status = dbItem.Status; Airport = dbItem.Airport; CompanyAirways = dbItem.Company_Airways; }
public Crew GetDbObject(Crew dbItem) { dbItem.Barcode = this.Barcode; dbItem.Nama = this.NamaCrew; dbItem.Tanggal_Daftar = this.TanggalDaftar; dbItem.Status = this.Status; dbItem.Airport = this.Airport; dbItem.Company_Airways = this.CompanyAirways; return dbItem; }
public void Save(Crew dbItem) { if (FindByPk(dbItem.Barcode) == null) //create { context.Crews.Add(dbItem); } else //edit { var entry = context.Entry(dbItem); entry.State = EntityState.Modified; } context.SaveChanges(); }
public ActionResult CreateCrew(CrewFormStub model) { //bool isNameExist = RepoContractor.Find().Where(p => p.name == model.Name).Count() > 0; if (ModelState.IsValid) { Crew dbItem = new Crew(); dbItem = model.GetDbObject(dbItem); //Generate ID untuk Crew string barcode = DateTime.Now.ToString("ddMMyyyy"); dbItem.Barcode = barcode + "-" + (RepoCrew.FindAll().Count + 1).ToString("D3"); try { RepoCrew.Save(dbItem); } catch (Exception e) { return View("FormCrew", model); } //message string template = HttpContext.GetGlobalResourceObject("MyGlobalMessage", "CreateSuccess").ToString(); this.SetMessage(model.NamaCrew, template); return RedirectToAction("CrewCRUD"); } else { return View("FormCrew", model); } }
public void Delete(Crew dbItem) { context.Crews.Remove(dbItem); context.SaveChanges(); }