public void Update(AcademyProgramViewModel academyProgram) { var program = _academyProgramRepository.FindById(academyProgram.ID); if (program == null) { throw new Exception("academyProgram is null"); } program.StartDate = academyProgram.StartDate; program.EndDate = academyProgram.EndDate; program.IsCurrent = academyProgram.IsCurrent; program.AcademyId = academyProgram.AcademyId; program.Academy = _academyrepository.FindById(academyProgram.AcademyId); _academyProgramRepository.Update(program); // if this AP is set to Current, update the latest current AP to IsCurrent=false /*if (academyProgram.IsCurrent) * { * var academyPrograms = _academyProgramRepository.GetAll().Where(ap => ap.IsCurrent && ap.ID != program.ID).ToList(); * foreach (var item in academyPrograms) * { * item.IsCurrent = false; * _academyProgramRepository.Update(item); * } * }*/ }
public ActionResult UpdateAcademyProgram(AcademyProgramViewModel academyProgram) { try { _academyProgramService.Update(academyProgram); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public static AcademyProgram ToDomain(this AcademyProgramViewModel model) { return(new AcademyProgram { ID = model.ID, CreatedOn = model.CreatedOn, CreatedBy = model.CreatedBy, StartDate = model.StartDate, EndDate = model.EndDate, IsCurrent = model.IsCurrent, AcademyId = model.AcademyId }); }
public void Create(AcademyProgramViewModel academyProgram) { if (academyProgram == null) { throw new ApplicationException("academyProgram is null"); } var program = academyProgram.ToDomain(); //program.CreatedBy = 1; program.Academy = _academyrepository.FindById(academyProgram.AcademyId); _academyProgramRepository.Create(program); }