public bool AssignGoal(AssignGoal AssignData)
 {
     try
     {
         int count = 0;
         bool MissingRes = false;
         foreach (int id in AssignData.ResourceID)
         {
             var v = _repository.GetResourceGoalDetailsDB(id, AssignData.Goal_MasterID);
             var ResGoal = GetAllGoalsOfResource(id);
             int TotalWeight = 0;
             if (ResGoal != null && ResGoal.Count > 0)
             {
                 TotalWeight = ResGoal.Sum(s => s.Weight) + AssignData.Weight;
             }
             if (v == null)
             {
                 if (TotalWeight >= 100)
                 {
                     MissingRes = true;
                     count++;
                 }
                 else
                 {
                     var resGoalModel = AutoMapper.Mapper.DynamicMap<AssignGoal, ResourceGoalModel>(AssignData);
                     resGoalModel.ResourceID = id;
                     resGoalModel.GoalAssignDate = DateTime.Now;
                     var AssignGoal = _repository.AssignGoalToResourceDB(resGoalModel);
                     if (AssignGoal != null)
                         count++;
                 }
             }
         }
         if (count == AssignData.ResourceID.Count())
         {
             if (MissingRes)
             {
                 this.ClearValidationErrors();
                 this.ValidationErrors.Add("ERR_GRT_TRGT", "Some Resouce weight is greter than 100 !");
                 return false;
             }
             return true;
         }
         else
         {
             this.ClearValidationErrors();
             this.ValidationErrors.Add("GoalNotAssigned", "Not all Goal were assigned Succesfully!");
             return false;
         }
     }
     catch
     {
         this.ValidationErrors.Add("ExceptionGoalAssign", "Error occured while Assigning a Goal!");
         return false;
     }
 }
Esempio n. 2
0
 public void AssignGoalTest()
 {
     int[] ResId = { 12 };
     AssignGoal Goal = new AssignGoal();
     Goal.Goal_MasterID = 3;
     Goal.ResourceID = ResId;
     Goal.Weight = 60;
     bool isAssigned = _rgService.AssignGoal(Goal);
     Assert.AreEqual(isAssigned, true);
 }
 public JsonResult AssignGoal(AssignGoal AssignData)
 {
     try
     {
         _assignGoalServices.ClearValidationErrors();
         var ISAssign = _assignGoalServices.AssignGoal(AssignData);
         if (ISAssign)
         {
             return Json(new JsonResponse { message = "Assign Goal Succesfully", success = true });
         }
         else
         {
             return Json(new JsonResponse { message = _assignGoalServices.ValidationErrors.Errors[0].ErrorDescription, success = false });
         }
     }
     catch
     {
         return Json(new JsonResponse { message = "Error occured while Assign a Goal", success = false });
     }
 }