Пример #1
0
        private Boolean CheckAvailabilityOfSiInLocalPurchase(string siNumber)
        {
            var shippingInstructionID = _shippingInstructionService.FindBy(m => m.Value == siNumber).FirstOrDefault().ShippingInstructionID;

            try
            {
                var siId = _localPurchaseService.FindBy(d => d.ShippingInstructionID == shippingInstructionID).SingleOrDefault();
                if (siId == null)
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #2
0
        public virtual ActionResult NotUnique(string SINumber, int GiftCertificateID)
        {
            var shippingInstruction = _shippingInstructionService.FindBy(t => t.Value == SINumber).FirstOrDefault();
            var gift = new Cats.Models.Hubs.GiftCertificate();

            if (shippingInstruction != null)
            {
                gift = _giftCertificateService.FindBySINumber(shippingInstruction.ShippingInstructionID);
            }
            UserProfile user = _userProfileService.GetUser(User.Identity.Name);
            bool        inReceiptAllocation = _receiptAllocationService.FindBySINumber(SINumber).Any(p => p.CommoditySourceID ==
                                                                                                     CommoditySource.Constants.LOCALPURCHASE);

            if ((gift == null || (gift.GiftCertificateID == GiftCertificateID)) && !(inReceiptAllocation))// new one or edit no problem
            {
                return(Json(true, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(string.Format("{0} is invalid, there is an existing record with the same SI Number ", SINumber),
                            JsonRequestBehavior.AllowGet));
            }
        }
Пример #3
0
        public ActionResult Create(ReceiptAllocationViewModel receiptAllocationViewModel)
        {
            if (receiptAllocationViewModel.CommoditySourceID == CommoditySource.Constants.DONATION)
            {
                ModelState.Remove("SourceHubID");
                ModelState.Remove("SupplierName");
                ModelState.Remove("PurchaseOrder");
            }
            else if (receiptAllocationViewModel.CommoditySourceID == CommoditySource.Constants.LOCALPURCHASE)
            {
                ModelState.Remove("DonorID");
                ModelState.Remove("SourceHubID");
            }
            else
            {
                ModelState.Remove("DonorID");
                ModelState.Remove("SupplierName");
                ModelState.Remove("PurchaseOrder");
            }

            if (!(IsSIValid(receiptAllocationViewModel.SINumber, receiptAllocationViewModel.CommoditySourceID)))
            {
                ModelState.AddModelError("SINumber", "");
            }

            if (ModelState.IsValid)
            {
                ReceiptAllocation receiptAllocation = receiptAllocationViewModel.GenerateReceiptAllocation();
                //for creation make the giftCetificate null if it's from
                if (receiptAllocationViewModel.GiftCertificateDetailID == 0 ||
                    receiptAllocationViewModel.GiftCertificateDetailID == null
                    )
                {
                    var shippingInstruction =
                        _shippingInstructionService.FindBy(t => t.Value == receiptAllocationViewModel.SINumber).
                        FirstOrDefault();
                    var GC = new GiftCertificate();
                    if (shippingInstruction != null)
                    {
                        GC = _giftCertificateService.FindBySINumber(shippingInstruction.ShippingInstructionID);
                    }

                    if (GC != null)
                    {
                        var GCD =
                            GC.GiftCertificateDetails.FirstOrDefault(
                                p => p.CommodityID == receiptAllocationViewModel.CommodityID);
                        if (GCD != null) //&& GCD.GiftCertificateDetailID;
                        {
                            receiptAllocation.GiftCertificateDetailID = GCD.GiftCertificateDetailID;
                        }
                    }
                    else
                    {
                        receiptAllocation.GiftCertificateDetailID = null;
                    }
                }
                int typeOfGridToReload = receiptAllocation.CommoditySourceID;
                int commType           = _commodityService.FindById(receiptAllocation.CommodityID).CommodityTypeID;
                //override to default hub
                UserProfile user = _userProfileService.GetUser(User.Identity.Name);
                receiptAllocation.HubID = user.DefaultHub.HubID;

                if (typeOfGridToReload != Cats.Models.Hubs.CommoditySource.Constants.DONATION &&
                    typeOfGridToReload != Cats.Models.Hubs.CommoditySource.Constants.LOCALPURCHASE)
                {
                    typeOfGridToReload = Cats.Models.Hubs.CommoditySource.Constants.LOAN;
                }
                receiptAllocation.ReceiptAllocationID = Guid.NewGuid();
                _receiptAllocationService.AddReceiptAllocation(receiptAllocation);

                return(Json(new { gridId = typeOfGridToReload, CommodityTypeID = commType }, JsonRequestBehavior.AllowGet));
                //return RedirectToAction("Index");
            }
            //check this out later
            //return this.Create(receiptAllocationViewModel.CommoditySourceID);
            //ModelState.Remove("SINumber");
            //TODO:Check if commenting out has any effect
            //=================================================
            //receiptAllocationViewModel.InitalizeViewModel();
            //================================================
            return(PartialView(receiptAllocationViewModel));
        }