예제 #1
0
        public bool Delete(SIPCAllocation allocation)
        {
            try
            {
                _unitOfWork.SIPCAllocationRepository.Delete(allocation);
                _unitOfWork.Save();
                return true;
            }
            catch (Exception e)
            {

            }
            return false;
        }
예제 #2
0
        public bool Create(SIPCAllocation allocation)
        {
            _unitOfWork.SIPCAllocationRepository.Add(allocation);
            _unitOfWork.Save();
            try
            {
            //                _unitOfWork.SIPCAllocationRepository.Add(allocation);
             //               _unitOfWork.Save();
                return true;
            }
            catch (Exception e)
            {

            }
            return false;
        }
예제 #3
0
 public ActionResult UpdateAllocation(List<SIPCAllocationViewModel> allocations)
 {
     //SIPCAllocation allocation2 = _allocationService.FindById(6);
        // int RequisitionID = 1;
     foreach(SIPCAllocationViewModel item in allocations)
     {
         if (item.SIPCAllocationID > 0)
         {
             SIPCAllocation allocation = _allocationService.FindById(item.SIPCAllocationID);
             if (item.AllocatedAmount == 0)
             {
                 _allocationService.Delete(allocation);
             }
             else
             {
                 allocation.Code = item.Code;
                 allocation.AllocatedAmount = item.AllocatedAmount;
                 allocation.AllocationType = item.AllocationType;
                 _allocationService.Update(allocation);
             }
         }
         else
         {
             if (item.AllocatedAmount > 0)
             {
                 SIPCAllocation allocation = new SIPCAllocation {
                     Code = item.Code,
                     AllocatedAmount = item.AllocatedAmount,
                     AllocationType = item.AllocationType,
                     RequisitionDetailID = item.RequisitionDetailID
                 };
                 _allocationService.Create(allocation);
             }
         }
     }
     //List<RequestAllocationViewModel> list = getIndexList(regionId, RequisitionID);
     return Json(allocations, JsonRequestBehavior.AllowGet);
 }
예제 #4
0
        public bool CreateRequisitonForTransfer(Transfer transfer)
        {
            if (transfer != null)
               {
               var fdp = _unitOfWork.FDPRepository.FindBy(m => m.HubID == transfer.DestinationHubID).FirstOrDefault();
               if (fdp != null)
               {
                   List<LedgerService.AvailableShippingCodes> availableSINumbers=new List<LedgerService.AvailableShippingCodes>();
                   var relifRequisition = new ReliefRequisition()
                       {

                           //RegionalRequestID = regionalRequest.RegionalRequestID,
                           //Round = regionalRequest.Round,
                           Month = transfer.CreatedDate.Month,
                           ProgramID = transfer.ProgramID,
                           CommodityID = transfer.CommodityID,
                           RequestedDate = transfer.CreatedDate,
                           //RationID = regionalRequest.RationID

                           RequisitionNo = Guid.NewGuid().ToString(),
                           RegionID = fdp.AdminUnit.AdminUnit2.AdminUnit2.AdminUnitID,
                           ZoneID = fdp.AdminUnit.AdminUnit2.AdminUnitID,
                           Status = (int) ReliefRequisitionStatus.Draft,

                       };
                   _unitOfWork.ReliefRequisitionRepository.Add(relifRequisition);

                   var relifRequistionDetail = new ReliefRequisitionDetail();

                   relifRequistionDetail.DonorID = 1;

                   relifRequistionDetail.FDPID = fdp.FDPID;

                   relifRequistionDetail.BenficiaryNo = 0; //since there is no need of benficiaryNo on transfer
                   relifRequistionDetail.CommodityID = transfer.CommodityID;
                   relifRequistionDetail.Amount = transfer.Quantity;
                   relifRequisition.ReliefRequisitionDetails.Add(relifRequistionDetail);

                   // save hub allocation
                   var hubAllocation = new HubAllocation
                       {
                           AllocatedBy = 1,
                           RequisitionID = relifRequisition.RequisitionID,
                           AllocationDate = transfer.CreatedDate,
                           ReferenceNo = "001",
                           HubID = transfer.SourceHubID
                       };
                   _unitOfWork.HubAllocationRepository.Add(hubAllocation);
                   //relifRequisition.RequisitionNo = String.Format("REQ-{0}", relifRequisition.RequisitionID);
                   relifRequisition.RequisitionNo = transfer.ReferenceNumber;
                   relifRequisition.Status = (int)ReliefRequisitionStatus.HubAssigned;
                   if(transfer.Commodity.ParentID==null)
                   {
                       availableSINumbers = GetFreeSICodesByCommodity(transfer.SourceHubID, transfer.CommodityID);
                   }
                   else
                   {
                       availableSINumbers = GetFreeSICodesByCommodityChild(transfer.SourceHubID, transfer.CommodityID);
                   }

                   var siNumberExist = availableSINumbers.Any(availableShippingCode => availableShippingCode.siCodeId == transfer.ShippingInstructionID);

                   if (!siNumberExist)
                   {
                       return false;
                   }
                   _unitOfWork.Save();

                   SIPCAllocation allocation = new SIPCAllocation
                   {
                       Code = transfer.ShippingInstructionID,
                       AllocatedAmount = transfer.Quantity,
                       AllocationType = "SI",
                       RequisitionDetailID = relifRequistionDetail.RequisitionDetailID
                   };
                   _unitOfWork.SIPCAllocationRepository.Add(allocation);

                   relifRequisition.Status = (int) ReliefRequisitionStatus.ProjectCodeAssigned;
                   relifRequisition.RequisitionNo = String.Format("REQ-{0}", relifRequisition.RequisitionID);
                   _unitOfWork.Save();
                   if (!PostSIAllocation(relifRequisition.RequisitionID,transfer.CommoditySourceID))
                   {
                       return false;
                   }
                   return true;

               }
               }
               return false;
        }