Exemple #1
0
        public async Task <Object> AddProjectMilestone([FromRoute] string projectId, [FromBody] AspNetMilestones newMilestone)
        {
            using (var ctx = new AckeeCtx())
            {
                var project = ctx.Projects.FirstOrDefault(p => p.ProjectID == projectId);

                if (project == null || string.IsNullOrWhiteSpace(newMilestone.MilestoneName))
                {
                    return(BadRequest());
                }

                newMilestone.Project = project;

                ctx.Milestones.Add(newMilestone);
                await ctx.SaveChangesAsync();

                return(newMilestone);
            }
        }
Exemple #2
0
        public async Task <Object> UpdateMilestoneById([FromRoute] string milestoneId, [FromBody] AspNetMilestones updatedMilestone)
        {
            using (var ctx = new AckeeCtx())
            {
                if (string.IsNullOrEmpty(updatedMilestone.MilestoneName))
                {
                    return(BadRequest());
                }

                // Get the milestone
                var milestone = await ctx.Milestones.FirstOrDefaultAsync(m => m.MilestoneID == milestoneId);

                // Update the milestone
                milestone.MilestoneName = updatedMilestone.MilestoneName;
                milestone.Description   = updatedMilestone.Description;
                milestone.EndDate       = updatedMilestone.EndDate;
                milestone.Completed     = updatedMilestone.Completed;

                // Save changes
                await ctx.SaveChangesAsync();

                return(true);
            }
        }