Beispiel #1
0
        public async Task AddObjective_Submit()
        {
            var objective = await scoreboard.AddAsync(Id, _objectiveForm.Name);

            _scoreboard.Add(objective);
            _objectiveForm = new ObjectiveViewModel();
        }
Beispiel #2
0
        public async Task <ActionResult> Objective(int id)
        {
            ObjectiveViewModel model = new ObjectiveViewModel();

            List <String> destNames = new List <String>()
            {
                indexDestName
            };

            model.Parser = HomeController.CreateBBCodeParser();

            model.Objective = objectiveService.GetObjectiveByID(id);

            if (User.Identity.IsAuthenticated && User.IsInRole("Admin"))
            {
                model.Initialize((await objectiveService.GetCurrentUser()), CreateObjectivesAdminNavList(destNames));
            }
            else
            {
                model.Initialize((await objectiveService.GetCurrentUser()), CreateObjectivesNavList(destNames));
            }

            model.BalanceEntries = model.SkipAndTake <BalanceEntry>(model.Objective.BalanceEntries.OrderByDescending(b => b.Date));

            if (model.Objective == null)
            {
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public ActionResult Index(string resumeGUID)
        {
            try
            {
                if (resumeGUID == null || string.IsNullOrWhiteSpace(resumeGUID))
                {
                    resumeGUID = "6257B7B5-C4D0-4D00-ACB4-350A95861B7F";
                }
                var                 viewModel       = new ObjectiveViewModel();
                Repository          _repositoryMain = new Repository(_connectionString);
                ObjectiveRepository _repository     = new ObjectiveRepository(_connectionString);

                Applicant            applicant      = _repositoryMain.GetApplicant(resumeGUID);
                List <ObjectiveItem> objectivesList = _repository.GetObjectives(resumeGUID);

                viewModel.Objectives = objectivesList;
                viewModel.Applicant  = applicant;

                return(View(viewModel));
            }
            catch
            {
                return(View("Error"));
            }
        }
        public async Task <IActionResult> Delete([FromBody] ObjectiveViewModel model)
        {
            try
            {
                var item = await _dm.ObjectiveAccessor.GetObjective(model.Id);

                if (item == null)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResultCode.NotFound
                    }));
                }

                await _dm.ObjectiveAccessor.DeleteItem(item.Id);

                return(Ok(new ResponseModel()
                {
                    Result = ResultCode.Success
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new ResponseModel()
                {
                    Result = ResultCode.ServerError
                }));
            }
        }
        public async Task <IActionResult> GetObjective([FromRoute] int id)
        {
            try
            {
                var item = await _dm.ObjectiveAccessor.GetObjective(id);

                if (item == null)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResultCode.NotFound
                    }));
                }


                ObjectiveViewModel model = item.ToObjectiveViewModel();

                return(Ok(model));
            }
            catch (Exception ex)
            {
                return(Ok(new ResponseModel()
                {
                    Result = ResultCode.ServerError, Description = ex.Message
                }));
            }
        }
Beispiel #6
0
        public async Task <ActionResult> Objective(ObjectiveViewModel model, int id)
        {
            List <String> destNames = new List <String>()
            {
                indexDestName
            };

            model.Parser    = HomeController.CreateBBCodeParser();
            model.Objective = objectiveService.GetObjectiveByID(id);

            if (User.Identity.IsAuthenticated && User.IsInRole("Admin"))
            {
                model.Initialize((await objectiveService.GetCurrentUser()), CreateObjectivesAdminNavList(destNames));
            }
            else
            {
                model.Initialize((await objectiveService.GetCurrentUser()), CreateObjectivesNavList(destNames));
            }


            if (model.Objective == null)
            {
                return(RedirectToAction("Index"));
            }

            model.BalanceEntries = model.SkipAndTake <BalanceEntry>(model.Objective.BalanceEntries.OrderByDescending(b => b.Date));

            // Clear the ModelState so changes in the model are reflected when using HtmlHelpers (their default behavior is to not use changes made to the model when re-rendering a view, not what we want here)
            ModelState.Clear();

            return(View(model));
        }
Beispiel #7
0
        public async Task <int> Put(ObjectiveViewModel model)
        {
            var entry = _mapper.Map <Objective>(model);
            await _unitOfWork.Objectives.Put(entry);

            return(await _unitOfWork.CompleteAsync());
        }
Beispiel #8
0
        public async Task <ResponseModel> SaveObjective(ObjectiveViewModel model)
        {
            string uri     = "api/objective/Save";
            var    request = await _http.PostAsJsonAsync <ObjectiveViewModel>(uri, model);

            var response = await request.Content.ReadFromJsonAsync <ResponseModel>();

            return(response);
        }
        public ActionResult Details(int id)
        {
            ObjectiveViewModel objective = _objWorkerSvc.GetObjectiveByID(id);

            if (objective == null)
            {
                return(HttpNotFound());
            }

            return(View(objective));
        }
        public async Task <JsonResult> EditObjective(ObjectiveViewModel objective)
        {
            if (ModelState.IsValid)
            {
                Objective _objective = AutoMapperConfiguration.Mapper.Map <Objective>(objective);
                bool      result     = await _objectiveService.EditObjective(_objective);

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Beispiel #11
0
        public HttpResponseMessage CreateObjective(HttpRequestMessage request, ObjectiveViewModel objectiveVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var goal = _goalRepository.GetSingle(objectiveVm.GoalId);

                    if (goal == null)
                    {
                        response = request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid goalId provided");
                    }
                    else if (objectiveVm.Estimation > goal.RemainingEstimates)
                    {
                        response = request.CreateErrorResponse(HttpStatusCode.BadRequest, "You don't have physical time to accomplish this objective according to the goal remaining estimates. Please add an extra effort time to your goal.");
                    }
                    else
                    {
                        TimeSpan totalObjectiveEstimate = goal.Objectives.Aggregate(TimeSpan.Zero, (current, objective) => current + objective.Estimation);

                        if (objectiveVm.Estimation > (goal.Estimation - totalObjectiveEstimate))
                        {
                            response = request.CreateErrorResponse(HttpStatusCode.BadRequest, "You don't have physical time to accomplish this objective according to the goal remaining estimates. Please add an extra effort time to your goal.");
                        }
                        else
                        {
                            Objective newObjective = new Objective();
                            newObjective.CreateObjective(objectiveVm);
                            newObjective.Goal = goal;

                            _objectiveRepository.Add(newObjective);
                            UnitOfWork.Commit();

                            //Update the goal
                            goal.Objectives.Add(newObjective);
                            _goalRepository.Edit(goal);
                            UnitOfWork.Commit();

                            objectiveVm = Mapper.Map <Objective, ObjectiveViewModel>(newObjective);
                            response = request.CreateResponse(HttpStatusCode.OK, objectiveVm);
                        }
                    }
                }

                return response;
            }));
        }
Beispiel #12
0
 public static void CreateObjective(this Objective objective, ObjectiveViewModel objectiveVm)
 {
     objective.Description        = objectiveVm.Description;
     objective.Estimation         = objectiveVm.Estimation;
     objective.ObjectiveRank      = objectiveVm.ObjectiveRank;
     objective.Title              = objectiveVm.Title;
     objective.DateCreated        = DateTime.Now;
     objective.ExtraTime          = TimeSpan.Zero;
     objective.RemainingEstimates = objectiveVm.Estimation;
     objective.ObjectiveStatus    = Status.Open;
     objective.Progress           = 0;
     objective.GoalId             = objectiveVm.GoalId;
 }
Beispiel #13
0
        public static ObjectiveViewModel ToObjectiveViewModel(this ObjectiveEntity entity)
        {
            ObjectiveViewModel model = new ObjectiveViewModel();

            model.Id              = entity.Id;
            model.Name            = entity.Name;
            model.Magnification   = entity.Magnification;
            model.Resolution      = entity.Resolution;
            model.EyePiece        = entity.EyePiece;
            model.ObjectiveLens   = entity.ObjectiveLens;
            model.DescriptionFORM = entity.Description;

            return(model);
        }
Beispiel #14
0
        public async Task <ActionResult> Details(Guid id)
        {
            var objective = await _objectivesRepository.GetObjectiveById(id);

            var model = new ObjectiveViewModel
            {
                Id         = objective.Id,
                Title      = objective.Title,
                Created    = objective.Created,
                KeyResults = objective.KeyResults.Select(y => new KeyResultListItemViewModel {
                    Id = y.Id, Description = y.Description
                }).ToList()
            };

            return(View(model));
        }
Beispiel #15
0
        public static ObjectiveEntity ToObjectiveEntity(this ObjectiveViewModel model)
        {
            ObjectiveEntity entity = new ObjectiveEntity();

            if (model.Id > 0)
            {
                entity.Id = model.Id;
            }
            entity.Name          = model.Name;
            entity.Magnification = model.Magnification;
            entity.Resolution    = model.Resolution;
            entity.EyePiece      = model.EyePiece;
            entity.ObjectiveLens = model.ObjectiveLens;
            entity.Description   = model.DescriptionFORM;
            return(entity);
        }
        public async Task <IActionResult> Save([FromBody] ObjectiveViewModel model)
        {
            try
            {
                ObjectiveEntity entity = null;
                if (!ModelState.IsValid)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResultCode.NotValidData
                    }));
                }
                if (model.Id <= 0)
                {
                    entity = new ObjectiveEntity();
                }
                else
                {
                    entity = await _dm.ObjectiveAccessor.GetObjective(model.Id);

                    if (entity == null)
                    {
                        return(Ok(new ResponseModel()
                        {
                            Result = ResultCode.AlreadyExists
                        }));
                    }
                }
                var entityToSave = model.ToObjectiveEntity();

                await _dm.ObjectiveAccessor.SaveObjective(entityToSave);

                return(Ok(new ResponseModel()
                {
                    Result = ResultCode.Success
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new ResponseModel()
                {
                    Result = ResultCode.ServerError, Description = ex.Message
                }));
            }
        }
Beispiel #17
0
        public HttpResponseMessage UpdateObjective(HttpRequestMessage request, ObjectiveViewModel objectiveVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var objective = Mapper.Map <ObjectiveViewModel, Objective>(objectiveVm);

                    _objectiveRepository.Edit(objective);
                    UnitOfWork.Commit();

                    response = request.CreateResponse(HttpStatusCode.OK, "Goal was updated with success");
                }

                return response;
            }));
        }
        public static ResultMatrixViewModel UpdateResultMatrixViewModel(this ResultMatrixViewModel model, ClientFieldData[] formData)
        {
            var outcomeIdNew   = 0;
            var indicatorIdNew = 0;

            model.Components.Clear();

            var fieldsGroupedForComponent = formData.Where(x => !string.IsNullOrWhiteSpace(x.Id)).GroupBy(x => x.Id);

            foreach (var fieldsForComponent in fieldsGroupedForComponent)
            {
                var componentId = fieldsForComponent.Key;
                if (componentId.Contains("new-"))
                {
                    componentId = "0";
                }

                var newComponent = new ComponentViewModel()
                {
                    OperationId = model.OperationId,
                    ComponentId = componentId.ConvertToInt(),
                };
                model.Components.Add(newComponent);

                var field = fieldsForComponent.First(x => x.Name == "Component-OrderNumber");
                if (field != null)
                {
                    newComponent.OrderNumber = field.ConvertToInt();
                }

                field = fieldsForComponent.First(x => x.Name == "PriorityArea");
                newComponent.PriorityArea = field.ConvertToString();

                var fieldsGroupedForObjective = fieldsForComponent
                                                .Where(x => x.ExtraData.ContainsKey("data-persist-objectiveid"))
                                                .GroupBy(x => x.ExtraData.Single(y => y.Key == "data-persist-objectiveid"));
                foreach (var fieldsForObjective in fieldsGroupedForObjective)
                {
                    var objectiveId = fieldsForObjective.Key.Value;
                    if (objectiveId.Contains("new-"))
                    {
                        objectiveId = "0";
                    }

                    var newObjective = new ObjectiveViewModel()
                    {
                        ComponentId = newComponent.ComponentId,
                        ObjectiveId = objectiveId.ConvertToInt()
                    };
                    newComponent.Objectives.Add(newObjective);

                    field = fieldsForObjective.First(x => x.Name == "Objective-OrderNumber");
                    newObjective.OrderNumber = field.ConvertToInt();

                    field = fieldsForObjective.First(x => x.Name == "GovernmentPriority");
                    newObjective.GovernmentPriority = field.ConvertToString();

                    field = fieldsForObjective.First(x => x.Name == "countryStrategicObjective");
                    newObjective.CountryStrategicObjective = field.ConvertToString();

                    field = fieldsForObjective.First(x => x.Name == "countryStrategicObjectiveES");
                    newObjective.CountryStrategicObjectiveES = field.ConvertToString();

                    field = fieldsForObjective.FirstOrDefault(x => x.Name == "countryStrategicObjectivePT");
                    if (field != null)
                    {
                        newObjective.CountryStrategicObjectivePT = field.ConvertToString();
                    }

                    field = fieldsForObjective.FirstOrDefault(x => x.Name == "countryStrategicObjectiveFR");
                    if (field != null)
                    {
                        newObjective.CountryStrategicObjectiveFR = field.ConvertToString();
                    }

                    field = fieldsForObjective.FirstOrDefault(x => x.Name == "AssociatedExpiredCSObjective");
                    newObjective.AssociatedExpiredCSObjective = field.ConvertToNullableInt();

                    var fieldsGroupedForOutcome = fieldsForObjective
                                                  .Where(x => x.ExtraData.ContainsKey("data-persist-outcomeid"))
                                                  .GroupBy(x => x.ExtraData.Single(y => y.Key == "data-persist-outcomeid"));
                    foreach (var fieldsForOutcome in fieldsGroupedForOutcome)
                    {
                        var outcomeId = fieldsForOutcome.Key.Value;
                        if (outcomeId.Contains("new-"))
                        {
                            outcomeIdNew--;
                            outcomeId = outcomeIdNew.ToString();
                        }

                        field = fieldsForOutcome.First(x => x.Name == "ExpectedOutcome");
                        var ecpectedOutcome = field.ConvertToString();

                        var fieldsGroupedForIndicator = fieldsForOutcome
                                                        .Where(x => x.ExtraData.ContainsKey("data-persist-indicatorid"))
                                                        .GroupBy(x => x.ExtraData.Single(y => y.Key == "data-persist-indicatorid"));
                        foreach (var fieldsForIndicator in fieldsGroupedForIndicator)
                        {
                            var indicatorId = fieldsForIndicator.Key.Value;
                            if (indicatorId.Contains("new-"))
                            {
                                indicatorIdNew--;
                                indicatorId = indicatorIdNew.ToString();
                            }

                            var newOutcome = new ExpectedOutcomeIndicatorViewModel()
                            {
                                ComponentId       = newComponent.ComponentId,
                                ObjectiveId       = newObjective.ObjectiveId,
                                ExpectedOutcomeId = outcomeId.ConvertToInt(),
                                IndicatorId       = indicatorId.ConvertToInt()
                            };

                            newObjective.ExpectedOutcomeIndicators.Add(newOutcome);

                            newOutcome.ExpectedOutcome = ecpectedOutcome;

                            field = fieldsForIndicator.First(x => x.Name == "Indicator");
                            newOutcome.Indicator = field.ConvertToString();

                            field = fieldsForIndicator.First(x => x.Name == "UnitOfMeasure");
                            newOutcome.UnitOfMeasure = field.ConvertToString();

                            field = fieldsForIndicator.First(x => x.Name == "Baseline");
                            newOutcome.Baseline = field.ConvertToString();

                            field = fieldsForIndicator.First(x => x.Name == "BaselineYear");
                            newOutcome.BaselineYear = field.ConvertToString();

                            field             = fieldsForIndicator.First(x => x.Name == "Source");
                            newOutcome.Source = field.ConvertToString();

                            var linkedIndicators = fieldsForIndicator.Where(x => x.Name == "LinkedIndicator");

                            foreach (var linedField in linkedIndicators)
                            {
                                newOutcome.LinkedIndicators.Add(linedField.ConvertToInt());
                            }
                        }
                    }
                }
            }

            return(model);
        }
Beispiel #19
0
 public async void PutAsync([FromBody] ObjectiveViewModel value)
 {
     var objective = mapper.Map <ObjectiveViewModel, ObjectiveDTO>(value);
     await objectiveService.UpdateObjectiveAsync(objective);
 }