public ActionResult CreateProgram(ProgramCreate model) { var ctx = new ApplicationDbContext(); if (ctx.Academies.FirstOrDefault(a => a.Name == model.AcademyName) == null) { ModelState.AddModelError("AcademyName", "Please create the academy first or enter an academy that already exists"); return(View(model)); } var service = GetBrowsingService(); if (service.CreateProgram(model)) { return(RedirectToAction(nameof(Index))); } return(View(model)); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public int AddProgramNode(IDebugProgramNode2 pProgramNode) { // // Registers a program that can be debugged with the port it is running on. // LoggingUtils.PrintFunction(); try { IDebugProcess2 process; DebuggeeProgram program = pProgramNode as DebuggeeProgram; LoggingUtils.RequireOk(program.GetProcess(out process)); foreach (IDebugPortEvents2 connectionPoint in m_eventConnectionPoints.Values) { ProgramCreate debugEvent = new ProgramCreate(); Guid eventGuid = ComUtils.GuidOf(debugEvent); int handle = connectionPoint.Event(null, this, process, program, debugEvent, ref eventGuid); if (handle == unchecked ((int)0x80010108)) // RPC_E_DISCONNECTED { continue; // Connection point was previously used. } LoggingUtils.RequireOk(handle); } return(Constants.S_OK); } catch (Exception e) { LoggingUtils.HandleException(e); return(Constants.E_FAIL); } }
public bool CreateProgram(ProgramCreate model) { var ctx = new ApplicationDbContext(); int academyId = ctx.Academies.FirstOrDefault(a => a.Name == model.AcademyName).AcademyId; string createdBy = ctx.Users.FirstOrDefault(u => u.Id == _userId).UserName; Program entity = new Program { Name = model.Name, Type = model.Type, Prerequisite = model.Prerequisite, AcademyId = academyId, AcademyName = model.AcademyName, OwnerId = _userId, CreatedBy = createdBy }; _context.Programs.Add(entity); var changeCount = _context.SaveChanges(); return(changeCount == 1); }