public void GuardarScholarshipProgram(ScholarshipProgram model) { if (model.ScholarshipProgramId != 0) { _context.ScholarshipProgram.Update(model); } else { _context.Add(model); } //_context.Add(model); _context.SaveChanges(); }
public IActionResult GuardarPrograma(ScholarshipProgramModel model) { //var scholarshipProgramModel = CopyPropierties.Convert<ScholarshipProgramModel, ScholarshipProgram>(model); var scholarshipProgramModel = new ScholarshipProgram { ScholarshipProgramId = model.ScholarshipProgramId, ScholarshipProgramName = model.ScholarshipProgramName, ScholarshipLevelId = model.ScholarshipLevelId, CreationDate = model.CreationDate, UpgradeDate = model.UpgradeDate, StatusId = model.StatusId, ScholarshipLevel = model.ScholarshipLevel, Status = model.Status, //ScholarshipProgramUniversit = model.ScholarshipProgramUniversity //Status = model.Status, //ScholarshipProgramUniversity = model.ScholarshipProgramUniversityList, }; var ScholarshipProgramUniversity = model.ScholarshipProgramUniversity; try { if (ScholarshipProgramUniversity != null) { ScholarshipProgramUniversity.ScholarshipProgramId = model.ScholarshipProgramId; _scholarshipProgramUniversity.Save(ScholarshipProgramUniversity); } _scholarshipProgram.GuardarScholarshipProgram(scholarshipProgramModel); } catch (Exception e) { ViewBag.Nivel = new SelectList(_scholarshipLevel.ScholarshipsLevel, "ScholarshipLevelId", "ScholarshipLevelName"); ViewBag.Status = new SelectList(_status.Status, "StatusId", "StatusName"); ViewBag.University = new SelectList(_university.Universities, "UniversityId", "UniversityName"); return(View("Crear", model)); } var ScholarshipProgramList = _scholarshipProgram.GetAll.ToList(); return(View("Index", ScholarshipProgramList)); }
public IActionResult GuardarPrograma(ScholarshipProgramModel model, string prueba) { if (ModelState.IsValid) { var scholarshipProgramModel = new ScholarshipProgram { ScholarshipProgramId = model.ScholarshipProgramId, ScholarshipProgramName = model.ScholarshipProgramName, ScholarshipLevelId = model.ScholarshipLevelId, CreationDate = model.CreationDate, UpgradeDate = model.UpgradeDate, StatusId = model.StatusId, ScholarshipLevel = model.ScholarshipLevel, Status = model.Status, }; try { _scholarshipProgram.GuardarScholarshipProgram(scholarshipProgramModel); } catch (Exception e) { ViewBag.Nivel = new SelectList(_scholarshipLevel.ScholarshipsLevel, "ScholarshipLevelId", "ScholarshipLevelName"); ViewBag.Status = new SelectList(_status.Status, "StatusId", "StatusName"); ViewBag.University = new SelectList(_university.Universities, "UniversityId", "UniversityName"); return(View("Crear", model)); } } else { var errors = ModelState.Select(x => x.Value.Errors).FirstOrDefault(x => x.Count > 0).First(); EnviarMensaje.Enviar(TempData, "red", errors.ErrorMessage); ViewBag.Nivel = new SelectList(_scholarshipLevel.ScholarshipsLevel, "ScholarshipLevelId", "ScholarshipLevelName"); ViewBag.Status = new SelectList(_status.Status, "StatusId", "StatusName"); ViewBag.University = new SelectList(_university.Universities, "UniversityId", "UniversityName"); return(View("Crear", model)); } return(View("Index", _scholarshipProgram.GetAll.ToList())); }
public void GuardarScholarshipProgram(ScholarshipProgram model) { var now = DateTime.Now; if (model.ScholarshipProgramId != 0) { model.UpgradeDate = now; _context.ScholarshipProgram.Update(model); } else { model.CreationDate = now; model.StatusId = StatusValues.Activo; _context.Add(model); } //_context.Add(model); _context.SaveChanges(); }