Example #1
0
        public ProjectStep UpdateStatus(int id, ProjectStepStatus projectStepStatus, string login)
        {
            using (var db = new SquareContext())
            {
                var step = db.ProjectSteps.Include("Project").Include("Step").Where(a => a.Id == id).Single();

                // validate that the step can be changed
                switch (projectStepStatus)
                {
                    case ProjectStepStatus.Pending:
                        step.DateStarted = null;
                        step.Complete = false;
                        break;
                    case ProjectStepStatus.Working:
                        step.DateStarted = DateTime.Now;
                        step.Complete = false;
                        break;
                    case ProjectStepStatus.Complete:
                        step.DateStarted = step.DateStarted.HasValue ? step.DateStarted : DateTime.Now;
                        step.DateCompleted = DateTime.Now;
                        step.Complete = true;
                        break;
                }

                db.SaveChanges();

                return step;
            }
        }
Example #2
0
        public JsonResult UpdateStatus(int id /* project id */, int stepId, ProjectStepStatus projectStepStatus)
        {
            var validationResult = new ValidationChangeStatusResult() {IsValid = true};

            // load the project step
            var step = Db.ProjectSteps.Where(a => a.Id == stepId).SingleOrDefault();

            if (step == null)
            {
                validationResult.IsValid = false;
                validationResult.Errors.Add("Unable to find step");
                return Json(validationResult);
            }

            _projectService.UpdateStatus(stepId, projectStepStatus, CurrentUserId);

            validationResult.ProjectStepId = stepId;

            return Json(validationResult);
        }