public ActionResult Edit(int id, ProspectEdit model) { //var db = new SchoolService(); //ViewBag.SchoolID = new SelectList(db.GetAllSchools().ToList(), "SchoolID", "SchoolName"); if (!ModelState.IsValid) { return(View(model)); } if (model.ProspectID != id) { ModelState.AddModelError("", "ID Mismatch"); return(View(model)); } var service = CreateProspectService(); if (service.UpdateProspect(model)) { TempData["SaveResult"] = "The prospect was successfully updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "The prospect could not be updated."); return(View(model)); }
// UPDATE public bool UpdateProspect(ProspectEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Prospects .Single(e => e.ProspectID == model.ProspectID); entity.ProspectID = model.ProspectID; entity.FirstName = model.FirstName; entity.LastName = model.LastName; entity.Position = model.Position; //entity.School = model.School; entity.SchoolID = model.SchoolID; entity.Report = model.Report; entity.Grade = model.Grade; entity.BigBoard = model.BigBoard; return(ctx.SaveChanges() == 1); } }
//// GET : Prospect/Details/{lastname} //[Route("lastname")] //public ActionResult Details(string lastName) //{ // var svc = CreateProspectService(); // var model = svc.GetProspectByName(lastName); // return View(model); //} //// GET : Prospect/Details/{position} //[Route("position")] //public ActionResult DetailsByPosition(string position) //{ // var svc = CreateProspectService(); // var model = svc.GetProspectByPosition(position); // return View(model); //} //// GET : Prospect/Details/{school} //[Route("school")] //public ActionResult DetailsBySchool(string school) //{ // var svc = CreateProspectService(); // var model = svc.GetProspectsBySchool(school); // return View(model); //} // UPDATE // GET : Prospect/Edit/{id} public ActionResult Edit(int id) { var db = new SchoolService(); ViewBag.SchoolID = new SelectList(db.GetAllSchools().OrderBy(e => e.SchoolName), "SchoolID", "SchoolName"); var service = CreateProspectService(); var detail = service.GetProspectByID(id); var model = new ProspectEdit { ProspectID = detail.ProspectID, FirstName = detail.FirstName, LastName = detail.LastName, Position = detail.Position, School = detail.School, Report = detail.Report, Grade = detail.Grade, BigBoard = detail.BigBoard }; return(View(model)); }
public override bool Update() { ProspectEdit windowEdit = new ProspectEdit(this); windowEdit.ShowDialog(); if (windowEdit.DialogResult.HasValue && windowEdit.DialogResult.Value == true) { try { using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Database.MegaCastingAPIEntities.token); string json = JsonConvert.SerializeObject(this, Formatting.Indented); var buffer = System.Text.Encoding.UTF8.GetBytes(json); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = client.PutAsync(Database.MegeCastingDatabase.Current.T_E_PROSPECT_PRO.Path + "/" + this.PRO_ID, byteContent).Result; if (response.IsSuccessStatusCode) { var responseContent = response.Content; string json2 = responseContent.ReadAsStringAsync().Result; JObject rss = JObject.Parse(json2); T_E_PROSPECT_PRO searchResult = rss["prospect"].ToObject <T_E_PROSPECT_PRO>(); this.PRO_ID = searchResult.PRO_ID; if (this.clientAdd != null && this.addresse != null) { if (addresse.ADR_ID != 0) { this.addresse.Update(); clientAdd.ADR_ID = addresse.ADR_ID; } else { this.addresse.Create(); clientAdd.ADR_ID = addresse.ADR_ID; } if (clientAdd.PRO_ID != 0) { clientAdd.PRO_ID = this.PRO_ID; clientAdd.Update(); } else { clientAdd.PRO_ID = this.PRO_ID; clientAdd.Create(); } } if (this.partenaire != null) { if (partenaire.PRO_ID != 0) { partenaire.PRO_ID = this.PRO_ID; partenaire.Update(); } else { partenaire.PRO_ID = this.PRO_ID; partenaire.Create(); } } if (listContactAdd.Count > 0) { foreach (T_E_CONTACT_CTC item in listContactAdd) { if (item.CTC_ID == 0) { item.PRO_ID = this.PRO_ID; item.saveCreate(); } else { item.saveUpdate(); } } } return(true); } } return(false); } catch (Exception) { return(false); } } else { return(false); } }