Beispiel #1
0
        public async Task <IActionResult> PostProjectStatusHistory([FromBody] ProjectStatusHistory projectStatusHistory)
        {
            //if (!ModelState.IsValid)
            //{
            //  return BadRequest(ModelState);
            //}
            var editedProjectStatusHistory = projectStatusHistory;

            editedProjectStatusHistory.CreatedUserId = 1;

            var project = _context.Project.First(s => s.ProjectId == projectStatusHistory.ProjectId);


            if (project == null)
            {
                return(NotFound());
            }

            project.ProjectStatus         = projectStatusHistory.ProjectStatus;
            project.ProjectStage          = projectStatusHistory.ProjectStage;
            _context.Entry(project).State = EntityState.Modified;

            _context.ProjectStatusHistory.Add(editedProjectStatusHistory);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetProjectStatusHistory", new { id = projectStatusHistory.ProjectStatusHistoryId },
                                   editedProjectStatusHistory));
        }
Beispiel #2
0
        public async Task <IActionResult> PutProjectStatusHistory([FromRoute] int id,
                                                                  [FromBody] ProjectStatusHistory projectStatusHistory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != projectStatusHistory.ProjectStatusHistoryId)
            {
                return(BadRequest());
            }

            _context.Entry(projectStatusHistory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProjectStatusHistoryExists(id))
                {
                    return(NotFound());
                }
                throw;
            }

            return(NoContent());
        }
        /// <summary>
        /// Gets the previuos project status from history.
        /// </summary>
        /// <param name="projectId">The project identifier.</param>
        /// <returns></returns>
        public static int GetPreviuosProjectStatusFromHistory(int projectId)
        {
            using (StageBitzDB dataContext = new StageBitzDB())
            {
                var currentStatusHistory = (from psh in dataContext.ProjectStatusHistories
                                            where psh.ProjectId == projectId
                                            select psh).OrderByDescending(psh => psh.ProjectStatusHistoryId).Take(2);

                if (currentStatusHistory != null && currentStatusHistory.Count() == 2)
                {
                    ProjectStatusHistory projectStatusHistory = (ProjectStatusHistory)currentStatusHistory.AsEnumerable().Last();
                    return(projectStatusHistory.ProjectStatusCodeId);
                }
                return(0);
            }
        }