Пример #1
0
 public BaseResponse Delete(int id)
 {
     try
     {
         var planning = new MidtermStrategicPlanning { Id = id };
         DataContext.MidtermStrategicPlannings.Attach(planning);
         DataContext.MidtermStrategicPlannings.Remove(planning);
         DataContext.SaveChanges();
         return new BaseResponse
         {
             IsSuccess = true,
             Message = "You have been successfully delete the item"
         };
     }
     catch
     {
         return new BaseResponse
         {
             IsSuccess = false,
             Message = "An error occured, please contact adminstrator for further information"
         };
     }
 }
Пример #2
0
        public AddStageResponse SaveStage(AddStageRequest request)
        {
            try
            {

                var stage = request.MapTo<MidtermPhaseFormulationStage>();
                var formulation = new MidtermPhaseFormulation { Id = request.MidtermFormulationId };
                DataContext.MidtermPhaseFormulations.Attach(formulation);
                stage.MidtermPhaseFormulation = formulation;
                var interval = stage.EndDate.Value.Year - stage.StartDate.Value.Year + 1;
                var startYear = stage.StartDate.Value.Year;
                var endYear = stage.EndDate.Value.Year;
                if (request.Id != 0)
                {
                    stage = DataContext.MidtermPhaseFormulationStages.Include(x => x.MidtermPhaseFormulation)
                        .Include(x => x.MidtermStrategicPlannings)
                        .First(x => x.Id == request.Id);
                    request.MapPropertiesToInstance<MidtermPhaseFormulationStage>(stage);
                    //delete unnecessary plannings
                    foreach(var plan in stage.MidtermStrategicPlannings.ToList()){
                        if (plan.StartDate < stage.StartDate || plan.EndDate > stage.EndDate) {
                            stage.MidtermStrategicPlannings.Remove(plan);
                        }
                    }
                    //add new strategic plannings
                    for (var i = 0; i < interval; i++)
                    {
                        var planning = new MidtermStrategicPlanning
                        {
                            Title = "Annual Objective Planning",
                            StartDate = i == 0 ? stage.StartDate : new DateTime(startYear + i, 1, 1),
                            EndDate = i == interval - 1 ? stage.EndDate : new DateTime(startYear + i, 12, 1)
                        };
                        if (stage.MidtermStrategicPlannings.FirstOrDefault(x => x.StartDate == planning.StartDate &&
                            x.EndDate == planning.EndDate) == null)
                        {
                            stage.MidtermStrategicPlannings.Add(planning);
                        }
                    }
                }
                else
                {

                    for (var i = 0; i < interval; i++)
                    {
                        var planning = new MidtermStrategicPlanning
                        {
                            Title = "Annual Objective Planning",
                            StartDate = i == 0 ? stage.StartDate : new DateTime(startYear + i, 1, 1),
                            EndDate = i == interval - 1 ? stage.EndDate : new DateTime(startYear + i, 12, 1)
                        };
                        stage.MidtermStrategicPlannings.Add(planning);
                    }
                    DataContext.MidtermPhaseFormulationStages.Add(stage);
                }
                DataContext.SaveChanges();
                return new AddStageResponse
                {
                    IsSuccess = true,
                    Message = "You have been successfully add new stage",
                    Id = stage.Id,
                    Title = stage.Title,
                    Order = stage.Order,
                    Start = request.StartDate.HasValue ? request.StartDate.Value.ToString("MMM yyyy", CultureInfo.InvariantCulture) : "",
                    End = request.EndDate.HasValue? request.EndDate.Value.ToString("MMM yyyy", CultureInfo.InvariantCulture) : ""
                };
            }
            catch {
                return new AddStageResponse
                              {
                                  IsSuccess = false,
                                  Message = "An Error occured, please contact administrator for further information"
                              };
            }
        }
Пример #3
0
 public AddObjectiveResponse AddObejctive(AddObjectiveRequest request)
 {
     try
     {
         var objective = request.MapTo<MidtermStrategicPlanningObjective>();
         if (request.Id == 0)
         {
             var midtermPlanning = new MidtermStrategicPlanning { Id = request.MidtermPlanningId };
             DataContext.MidtermStrategicPlannings.Attach(midtermPlanning);
             objective.MidtermStrategicPlanning = midtermPlanning;
             DataContext.MidtermStrategicPlanningObjectives.Add(objective);
         }
         else {
             objective = DataContext.MidtermStrategicPlanningObjectives.First(x => x.Id == request.Id);
             request.MapPropertiesToInstance<MidtermStrategicPlanningObjective>(objective);
         }
         DataContext.SaveChanges();
         return new AddObjectiveResponse
         {
             IsSuccess = true,
             Message = "You have been successfully add Objective",
             Id = objective.Id,
             Value = objective.Value
         };
     }
     catch {
         return new AddObjectiveResponse
         {
             IsSuccess = false,
             Message = "An error occured, please contact adminstrator for further information"
         };
     }
 }