예제 #1
0
        // 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);
            }
        }
예제 #2
0
        public async Task <ActionResult <GoalDetail> > PostGoalDetail(GoalDetail goalDetail)
        {
            _context.GoalDetail.Add(goalDetail);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGoalDetail", new { id = goalDetail.ID }, goalDetail));
        }
예제 #3
0
        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());
        }
예제 #4
0
 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;
     }
 }
예제 #5
0
        // 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);
        }
예제 #6
0
 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();
 }