// Get by ID - Read public GoalDetail GetGoalById(int id) { EntryService entryService = new EntryService(); using (var ctx = new ApplicationDbContext()) { var entity = ctx .Goals .Single(e => e.GoalId == id); var detail = new GoalDetail { GoalId = entity.GoalId, GoalTitle = entity.GoalTitle, GoalContent = entity.GoalContent, GoalType = (Models.GoalModels.GoalType)entity.GoalType, Difficulty = entity.Difficulty, StartDate = entity.StartDate, EndDate = entity.EndDate, Completed = entity.Completed, ProfileId = entity.ProfileId, AllEntriesForGoal = ConvertDataEntitiesToViewModel(entity.AllEntriesForGoal.ToList()) }; return(detail); } }
public async Task <ActionResult <GoalDetail> > PostGoalDetail(GoalDetail goalDetail) { _context.GoalDetail.Add(goalDetail); await _context.SaveChangesAsync(); return(CreatedAtAction("GetGoalDetail", new { id = goalDetail.ID }, goalDetail)); }
public async Task <IActionResult> PutGoalDetail(int id, GoalDetail goalDetail) { if (id != goalDetail.ID) { return(BadRequest()); } _context.Entry(goalDetail).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GoalDetailExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void InsertOrUpdate(GoalDetail goalDetail) { if (goalDetail.Id == default(int)) { // New entity _context.GoalDetails.Add(goalDetail); } else { // Existing entity _context.Entry(goalDetail).State = EntityState.Modified; } }
// Access and read items from the Goal iCollection public List <GoalDetail> ConvertDataEntitiesToViewModel(List <Goal> goals) { List <GoalDetail> returnList = new List <GoalDetail>(); foreach (var goal in goals) { var goalDetail = new GoalDetail(); goalDetail.GoalId = goal.GoalId; goalDetail.GoalTitle = goal.GoalTitle; goalDetail.GoalContent = goal.GoalContent; goalDetail.GoalType = (Models.GoalModels.GoalType)goal.GoalType; goalDetail.Difficulty = goal.Difficulty; goalDetail.StartDate = goal.StartDate; goalDetail.EndDate = goal.EndDate; goalDetail.Completed = goal.Completed; returnList.Add(goalDetail); } return(returnList); }
public void Load <TElement>(GoalDetail goalDetail, Expression <Func <GoalDetail, ICollection <TElement> > > includeProperty) where TElement : class { _context.GoalDetails.Attach(goalDetail); _context.Entry(goalDetail).Collection(includeProperty).Load(); }