public ActionResult Edit(Air_ports model) { try { var record = dbcontext.Air_ports.FirstOrDefault(m => m.ID == model.ID); ViewBag.country = dbcontext.Country.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID }); ViewBag.area = new List <Area>(); ViewBag.state = new List <the_states>(); if (record.countryid > 0) { ViewBag.area = dbcontext.Area.Where(m => m.Countryid == record.countryid.ToString()).ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID }); } if (record.areaid > 0) { ViewBag.state = dbcontext.the_states.Where(m => m.Areaid == record.areaid.ToString()).ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID }); } if (model.the_statesid == "0" || model.the_statesid == null) { ModelState.AddModelError("", HR.Resource.Basic.StateCodemustenter); return(View(model)); } record.Name = model.Name; record.Description = model.Description; record.countryid = model.countryid; record.areaid = model.areaid; record.Code = model.Code; record.the_statesid = model.the_statesid; var the_statesid = int.Parse(model.the_statesid); record.the_states = dbcontext.the_states.FirstOrDefault(m => m.ID == the_statesid); dbcontext.SaveChanges(); //=================================check for alert================================== var get_result_check = HR.Controllers.check.check_alert("air port", HR.Models.user.Action.edit, HR.Models.user.type_field.form); if (get_result_check != null) { var inbox = new Models.user.Alert_inbox { send_from_user_id = User.Identity.Name, send_to_user_id = get_result_check.send_to_ID_user, title = get_result_check.Subject, Subject = get_result_check.Message }; if (get_result_check.until != null) { if (get_result_check.until.Value.Year != 0001) { inbox.until = get_result_check.until; } } ApplicationDbContext dbcontext = new ApplicationDbContext(); dbcontext.Alert_inbox.Add(inbox); dbcontext.SaveChanges(); } //=================================================================================== return(RedirectToAction("index")); } catch (DbUpdateException) { TempData["Message"] = HR.Resource.Basic.thiscodeIsalreadyexists; return(View(model)); } catch (Exception e) { return(View(model)); } }
public ActionResult Create() { ViewBag.country = dbcontext.Country.ToList().Select(m => new { Code = m.Code + "------[" + m.Name + ']', ID = m.ID }); ViewBag.area = new List <Area>(); ViewBag.state = new List <the_states>(); var modell = new Air_ports(); var stru = dbcontext.StructureModels.FirstOrDefault(m => m.All_Models == ChModels.Basic).Structure_Code; var model_ = dbcontext.Air_ports.ToList(); if (model_.Count() == 0) { modell.Code = stru + "1"; } else { modell.Code = stru + (model_.LastOrDefault().ID + 1).ToString(); } ///// return(View(modell)); }