Exemple #1
0
        public void AddNeedAssessmentPlan(NeedAssessment needAssessment)
        {
            var oldPlan = _unitOfWork.PlanRepository.FindBy(m => m.PlanName==needAssessment.Plan.PlanName).SingleOrDefault();
            if (oldPlan == null)
            {
                var program = _unitOfWork.ProgramRepository.FindBy(m => m.Name == "Relief");
                var plan = new Plan
                    {
                        PlanName = needAssessment.Plan.PlanName,
                        StartDate = needAssessment.Plan.StartDate,
                        EndDate = needAssessment.Plan.EndDate,
                        ProgramID = program.First().ProgramID,
                        Program = _unitOfWork.ProgramRepository.FindBy(m=>m.Name=="Relief").FirstOrDefault()

                    };

                var savePlan = _unitOfWork.PlanRepository.Add(plan);
                _unitOfWork.Save();
                //if (!savePlan)
                //{
                //    return null;
                //}
                //return plan;
            }
            //return oldPlan;
        }
        public ActionResult AddNeedAssessment(NeedAssessment needAssessment,FormCollection collection)
        {
            var region = collection["RegionID"].ToString(CultureInfo.InvariantCulture);
            var regionID = int.Parse(region);
            int season = int.Parse(collection["SeasonID"].ToString(CultureInfo.InvariantCulture));
            int planID = int.Parse(collection["PlanID"].ToString(CultureInfo.InvariantCulture));
            int typeOfNeedID = int.Parse(collection["TypeOfNeedID"].ToString(CultureInfo.InvariantCulture));
            var userID = _needAssessmentHeaderService.GetUserProfileId(HttpContext.User.Identity.Name);
            try
            {
            _needAssessmentService.AddNeedAssessment(needAssessment.PlanID, regionID, season, userID, typeOfNeedID);
            return RedirectToAction("Detail", "NeedAssessment", new { id = needAssessment.PlanID });
            }
            catch (Exception exception)
            {

            var log = new Logger();
            log.LogAllErrorsMesseges(exception, _log);
            //ViewBag.Regions = new SelectList(_adminUnitService.FindBy(t => t.AdminUnitTypeID == 2), "AdminUnitID", "Name");
            //ViewBag.Season = new SelectList(_seasonService.GetAllSeason(), "SeasonID", "Name");
            //ViewBag.TypeOfNeed = new SelectList(_typeOfNeedAssessmentService.GetAllTypeOfNeedAssessment(), "TypeOfNeedAssessmentID", "TypeOfNeedAssessment1");
            ViewBag.Error = "Need Assessment is already Created for this region";
            //ModelState.AddModelError("Errors", ViewBag.Error);
            return RedirectToAction("Detail", "NeedAssessment", new { id = needAssessment.PlanID });
            }
        }
        public void AddNeedAssessment(int planID, int regionID, int seasonID, int userID, int needAssessmentTypeID)
        {
            List<AdminUnit> zones = _unitOfWork.AdminUnitRepository.Get(t => t.ParentID == regionID).ToList();
            NeedAssessmentDetail detail = null;
            var needAssessment = new NeedAssessment
                {
                    PlanID = planID,
                    Region = regionID,
                    Season = seasonID,
                    NeddACreatedBy = userID,
                    NeedAApprovedBy = userID,
                    TypeOfNeedAssessment = needAssessmentTypeID,
                    NeedAApproved = false,
                    NeedADate = DateTime.Now,
                };
            _unitOfWork.NeedAssessmentRepository.Add(needAssessment);
            foreach (var adminUnit in zones)
            {
                var needAssessmentHeader = new NeedAssessmentHeader()
                    {
                        Zone = adminUnit.AdminUnitID,
                        NeedAssessment = needAssessment
                    };
                _unitOfWork.NeedAssessmentHeaderRepository.Add(needAssessmentHeader);

                var woredas = _unitOfWork.AdminUnitRepository.Get(t => t.ParentID == needAssessmentHeader.Zone).ToList();

                foreach (var woreda in woredas)
                {
                    detail = new NeedAssessmentDetail
                    {
                        //NeedAId = needAssessmentHeader.NAHeaderId,
                        NeedAssessmentHeader = needAssessmentHeader,
                        Woreda = woreda.AdminUnitID,
                        ProjectedMale = 0,
                        ProjectedFemale = 0,
                        RegularPSNP = 0,
                        PSNP = 0,
                        NonPSNP = 0,
                        Contingencybudget = 0,
                        TotalBeneficiaries = 0,
                        PSNPFromWoredasMale = 0,
                        PSNPFromWoredasFemale = 0,
                        PSNPFromWoredasDOA = 0,
                        NonPSNPFromWoredasMale = 0,
                        NonPSNPFromWoredasFemale = 0,
                        NonPSNPFromWoredasDOA = 0
                    };
                    _unitOfWork.NeedAssessmentDetailRepository.Add(detail);
                }
            }
            _unitOfWork.Save();
        }
 public ActionResult AddNeedAssessment(int id)
 {
     var needAssessment = _needAssessmentService.FindBy(m => m.PlanID == id).FirstOrDefault();
      ViewBag.TypeOfNeed = new SelectList(_typeOfNeedAssessmentService.GetAllTypeOfNeedAssessment(), "TypeOfNeedAssessmentID", "TypeOfNeedAssessment1");
      ViewBag.Regions = new SelectList(_adminUnitService.FindBy(t => t.AdminUnitTypeID == 2), "AdminUnitID", "Name");
      ViewBag.Season = new SelectList(_seasonService.GetAllSeason(), "SeasonID", "Name");
      if (needAssessment!=null)
      {
      return View(needAssessment);
      }
      var newAssessment = new NeedAssessment {PlanID = id};
      return View(newAssessment);
 }
 public bool AddNeedAssessment(NeedAssessment needAssessment)
 {
     try
     {
         _unitOfWork.NeedAssessmentRepository.Add(needAssessment);
         _unitOfWork.Save();
         return true;
     }
     catch (System.Data.ConstraintException ex)
     {
         Logger.Error("",new Exception(ex.InnerException.Message.ToString(CultureInfo.InvariantCulture)));
         throw new Exception(ex.ToString());
     }
 }
        public ActionResult CreateNeedAssessment(NeedAssessment needAssessment, FormCollection collection)
        {
            ViewBag.Error = "";
             var region = collection["RegionID"].ToString(CultureInfo.InvariantCulture);
             var regionID = int.Parse(region);
             int season = int.Parse(collection["SeasonID"].ToString(CultureInfo.InvariantCulture));
             int typeOfNeedID = int.Parse(collection["TypeOfNeedID"].ToString(CultureInfo.InvariantCulture));
             string planName = collection["Plan.PlanName"].ToString(CultureInfo.InvariantCulture);
             DateTime startDate = DateTime.Parse(collection["Plan.StartDate"].ToString(CultureInfo.InvariantCulture));
             var firstDayOfTheMonth = startDate.AddDays(1 - startDate.Day);
             var duration = int.Parse(collection["Plan.Duration"].ToString(CultureInfo.InvariantCulture));
             //DateTime endDate = DateTime.Parse(collection["Plan.EndDate"].ToString(CultureInfo.InvariantCulture));
             var endDate = firstDayOfTheMonth.AddMonths(duration);
             if (ModelState.IsValid)
             {
                 var existingPlan = _planService.FindBy(m => m.PlanName == planName && m.ProgramID==1).FirstOrDefault();
                 if (existingPlan != null)
                 {
                     ModelState.AddModelError("Errors", @"Needs Assessment Name already Exists Please Change the Name");
                 }
                 else
                 {

                     try
                     {
                         _planService.AddPlan(planName, firstDayOfTheMonth, endDate);
                         var plan = _planService.Get(p => p.PlanName == planName).Single();
                         var userID = _needAssessmentHeaderService.GetUserProfileId(HttpContext.User.Identity.Name);
                         _needAssessmentService.AddNeedAssessment(plan.PlanID, regionID, season, userID, typeOfNeedID);
                         return RedirectToAction("Index");
                     }

                     catch (Exception exception)
                     {
                         var log = new Logger();
                         log.LogAllErrorsMesseges(exception, _log);
                         ViewBag.Regions = new SelectList(_adminUnitService.FindBy(t => t.AdminUnitTypeID == 2),
                                                          "AdminUnitID", "Name");
                         ViewBag.Season = new SelectList(_seasonService.GetAllSeason(), "SeasonID", "Name");
                         ViewBag.TypeOfNeed = new SelectList(_typeOfNeedAssessmentService.GetAllTypeOfNeedAssessment(),
                                                             "TypeOfNeedAssessmentID", "TypeOfNeedAssessment1");
                         ViewBag.Error = "Need Assessment Already Exists Please Change Plan Name or Region Name";
                         ModelState.AddModelError("Errors", ViewBag.Error);
                         return View();
                     }
                 }

                 //return RedirectToAction("Edit", new { id = regionID, typeOfNeed = typeOfNeedID });
             }
            ViewBag.Regions = new SelectList(_adminUnitService.FindBy(t => t.AdminUnitTypeID == 2), "AdminUnitID", "Name");
               ViewBag.Season = new SelectList(_seasonService.GetAllSeason(), "SeasonID", "Name");
               ViewBag.TypeOfNeed = new SelectList(_typeOfNeedAssessmentService.GetAllTypeOfNeedAssessment(), "TypeOfNeedAssessmentID", "TypeOfNeedAssessment1");
            return View(needAssessment);
        }
 public ActionResult CreateNeedAssessment()
 {
     ViewBag.Regions = new SelectList(_adminUnitService.FindBy(t => t.AdminUnitTypeID == 2), "AdminUnitID", "Name");
     ViewBag.Season = new SelectList(_seasonService.GetAllSeason(), "SeasonID", "Name");
     ViewBag.TypeOfNeed = new SelectList(_typeOfNeedAssessmentService.GetAllTypeOfNeedAssessment(), "TypeOfNeedAssessmentID", "TypeOfNeedAssessment1");
     ViewBag.PlanID = new SelectList(_planService.GetAllPlan(), "PlanID", "PlanName");
     var needAssessement = new NeedAssessment();
     return View(needAssessement);
 }
        public bool GenerateDefefaultData(NeedAssessment needAssessment)
        {
            List<AdminUnit> zones = _unitOfWork.AdminUnitRepository.Get(t => t.ParentID == needAssessment.Region).ToList();
            NeedAssessmentDetail woreda = null;
            foreach (var adminUnit in zones)
            {
                var zone = new NeedAssessmentHeader
                               {
                                   NeedAID = needAssessment.NeedAID,
                                   Zone = adminUnit.AdminUnitID,

                               };

                var woredas =  _unitOfWork.AdminUnitRepository.Get(t => t.ParentID == zone.Zone).ToList();

                foreach (var _woreda in woredas)
                {
                     woreda = new NeedAssessmentDetail
                                  {
                                      NeedAId = zone.NAHeaderId,
                                      Woreda = _woreda.AdminUnitID,
                                      ProjectedMale = 0,
                                      ProjectedFemale = 0,
                                      RegularPSNP = 0,
                                      PSNP = 0,
                                      NonPSNP = 0,
                                      Contingencybudget = 0,
                                      TotalBeneficiaries = 0,
                                      PSNPFromWoredasMale = 0,
                                      PSNPFromWoredasFemale = 0,
                                      PSNPFromWoredasDOA = 0,
                                      NonPSNPFromWoredasMale = 0,
                                      NonPSNPFromWoredasFemale = 0,
                                      NonPSNPFromWoredasDOA = 0,
                                      NeedAssessmentHeader = zone
                                  };
                    woreda.NeedAssessmentHeader.NeedAssessment = needAssessment;

                    _unitOfWork.NeedAssessmentDetailRepository.Add(woreda);

                }
            }
              _unitOfWork.Save();

            return true;
        }
 public bool EditNeedAssessment(NeedAssessment needAssessment)
 {
     _unitOfWork.NeedAssessmentRepository.Edit(needAssessment);
     _unitOfWork.Save();
     return true;
 }
 public bool DeleteNeedAssessment(NeedAssessment needAssessment)
 {
     if (needAssessment == null) return false;
     _unitOfWork.NeedAssessmentRepository.Delete(needAssessment);
     _unitOfWork.Save();
     return true;
 }
        public ActionResult AddNeedAssessment(int id)
        {
            var needAssessment = _needAssessmentService.FindBy(m => m.PlanID == id).FirstOrDefault();
             ViewBag.TypeOfNeed = new SelectList(_typeOfNeedAssessmentService.GetAllTypeOfNeedAssessment(), "TypeOfNeedAssessmentID", "TypeOfNeedAssessment1");
             var userRegionID = _userAccountService.GetUserInfo(HttpContext.User.Identity.Name).RegionID;
             if (userRegionID != null)
             {
             ViewBag.Regions = new SelectList(_adminUnitService.FindBy(t => t.AdminUnitID == userRegionID), "AdminUnitID", "Name");
             }
             else
             {
             ViewBag.Regions = new SelectList(_adminUnitService.FindBy(t => t.AdminUnitTypeID == 2), "AdminUnitID", "Name");
             }

             ViewBag.Season = new SelectList(_seasonService.GetAllSeason(), "SeasonID", "Name");
             if (needAssessment!=null)
             {
             return View(needAssessment);
             }
             var newAssessment = new NeedAssessment {PlanID = id};
             return View(newAssessment);
        }
 public ActionResult CreateNeedAssessment()
 {
     var userRegionID = _userAccountService.GetUserInfo(HttpContext.User.Identity.Name).RegionID;
     if (userRegionID != null)
     {
         ViewBag.Regions = new SelectList(_adminUnitService.FindBy(t => t.AdminUnitID == userRegionID), "AdminUnitID", "Name");
     }
     else
     {
         ViewBag.Regions = new SelectList(_adminUnitService.FindBy(t => t.AdminUnitTypeID == 2), "AdminUnitID", "Name");
     }
     ViewBag.Season = new SelectList(_seasonService.GetAllSeason(), "SeasonID", "Name");
     ViewBag.TypeOfNeed = new SelectList(_typeOfNeedAssessmentService.GetAllTypeOfNeedAssessment(), "TypeOfNeedAssessmentID", "TypeOfNeedAssessment1");
     ViewBag.PlanID = new SelectList(_planService.GetAllPlan(), "PlanID", "PlanName");
     var needAssessement = new NeedAssessment();
     return View(needAssessement);
 }