Ejemplo n.º 1
0
 public bool DeleteRegionalPSNPPlanDetail(RegionalPSNPPlanDetail item)
 {
     if (item == null)
     {
         return(false);
     }
     _unitOfWork.RegionalPSNPPlanDetailRepository.Delete(item);
     _unitOfWork.Save();
     return(true);
 }
        public ActionResult EditAjax([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable <PSNPPlanDetailView> items)
        {
            int planId = 0;
            //var psnpPlan =
            //    _regionalPSNPPlanService.FindBy(m => m.RegionalPSNPPlanID == items.FirstOrDefault().RegionalPSNPPlanID).
            //        FirstOrDefault();
            List <PSNPPlanDetailView> updated = new List <PSNPPlanDetailView>();

            foreach (PSNPPlanDetailView item in items)
            {
                updated.Add(item);
                planId = item.RegionalPSNPPlanID;
                if (item.BeneficiaryCount > 0)
                {
                    RegionalPSNPPlanDetail bm;
                    if (item.RegionalPSNPPlanDetailID >= 1)
                    {
                        bm = _regionalPSNPPlanDetailService.FindById(item.RegionalPSNPPlanDetailID);
                        bm.StartingMonth = 1;  //set default month January
                        if (item.SartingMonth != 0)
                        {
                            bm.StartingMonth = item.SartingMonth;
                        }

                        bm.BeneficiaryCount = (int)item.BeneficiaryCount;
                        bm.FoodRatio        = (int)item.FoodRatio;
                        bm.CashRatio        = (int)item.CashRatio;

                        _regionalPSNPPlanDetailService.UpdateRegionalPSNPPlanDetail(bm);
                    }
                    else
                    {
                        bm = new RegionalPSNPPlanDetail();
                        bm.RegionalPSNPPlanID = item.RegionalPSNPPlanID;
                        bm.PlanedWoredaID     = item.WoredaID;
                        bm.BeneficiaryCount   = (int)item.BeneficiaryCount;
                        bm.FoodRatio          = (int)item.FoodRatio;
                        bm.CashRatio          = (int)item.CashRatio;
                        bm.StartingMonth      = 1; //set default month January
                        if (item.SartingMonth != 0)
                        {
                            bm.StartingMonth = item.SartingMonth;
                        }
                        var psnpPlanExist =
                            _regionalPSNPPlanDetailService.FindBy(
                                m => m.RegionalPSNPPlanID == item.RegionalPSNPPlanID && m.PlanedWoredaID == item.WoredaID).
                            FirstOrDefault();
                        if (psnpPlanExist == null)
                        {
                            _regionalPSNPPlanDetailService.AddRegionalPSNPPlanDetail(bm);
                        }
                    }
                }
                else
                {
                    if (item.RegionalPSNPPlanDetailID >= 0)
                    {
                        _regionalPSNPPlanDetailService.DeleteById(item.RegionalPSNPPlanDetailID);
                    }
                }
            }

            /*var allFDPData = getDetailView(planId);
             * return Json(new[] { regionalRequestDetail }.ToDataSourceResult(request, ModelState)); */
            return(Json(updated.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));

            // return Json(ModelState.ToDataSourceResult(request, ModelState));
        }
Ejemplo n.º 3
0
 public bool AddRegionalPSNPPlanDetail(RegionalPSNPPlanDetail item)
 {
     _unitOfWork.RegionalPSNPPlanDetailRepository.Add(item);
     _unitOfWork.Save();
     return(true);
 }