Пример #1
0
        /// <summary>
        /// Gifts the certificate model.
        /// </summary>
        /// <param name="GiftCertificateModel">The gift certificate model.</param>
        /// <returns></returns>
        public static GiftCertificateViewModel GiftCertificateModel(GiftCertificate GiftCertificateModel)
        {
            GiftCertificateViewModel giftCertificateViewModel = new GiftCertificateViewModel();

            giftCertificateViewModel.GiftCertificateID     = GiftCertificateModel.GiftCertificateID;
            giftCertificateViewModel.GiftDate              = GiftCertificateModel.GiftDate;
            giftCertificateViewModel.DonorID               = GiftCertificateModel.DonorID;
            giftCertificateViewModel.ShippingInstructionID = GiftCertificateModel.ShippingInstructionID;
            giftCertificateViewModel.ReferenceNo           = GiftCertificateModel.ReferenceNo;
            giftCertificateViewModel.Vessel           = GiftCertificateModel.Vessel;
            giftCertificateViewModel.ETA              = GiftCertificateModel.ETA;
            giftCertificateViewModel.ProgramID        = GiftCertificateModel.ProgramID;
            giftCertificateViewModel.PortName         = GiftCertificateModel.PortName;
            giftCertificateViewModel.DModeOfTransport = GiftCertificateModel.DModeOfTransport;
            var giftCertificateDetail = GiftCertificateModel.GiftCertificateDetails.FirstOrDefault();

            if (giftCertificateDetail != null)
            {
                giftCertificateViewModel.CommodityTypeID = giftCertificateDetail.Commodity.CommodityTypeID;
            }
            else
            {
                giftCertificateViewModel.CommodityTypeID = 1;//by default 'food'
            }
            giftCertificateViewModel.GiftCertificateDetails =
                GiftCertificateDetailsViewModel.GenerateListOfGiftCertificateDetailsViewModel(
                    GiftCertificateModel.GiftCertificateDetails.ToList());


            return(giftCertificateViewModel);
        }
Пример #2
0
        private void InsertGiftCertificate(Cats.Models.Hubs.GiftCertificateViewModel giftcertificate, GiftCertificate giftCertificateModel)
        {
            List <Cats.Models.Hubs.GiftCertificateDetailsViewModel> giftCertificateDetails = GetSelectedGiftCertificateDetails(giftcertificate.JSONInsertedGiftCertificateDetails);
            var giftDetails = GenerateGiftCertificate(giftCertificateDetails);

            foreach (GiftCertificateDetail giftDetail in giftDetails)
            {
                giftCertificateModel.GiftCertificateDetails.Add(giftDetail);
            }
            _giftCertificateService.AddGiftCertificate(giftCertificateModel);
        }
Пример #3
0
        public ActionResult Create(Cats.Models.Hubs.GiftCertificateViewModel giftcertificate)
        {
            if (ModelState.IsValid)
            {
                GiftCertificate giftCertificateModel = giftcertificate.GenerateGiftCertificate();

                InsertGiftCertificate(giftcertificate, giftCertificateModel);
                //repository.Add( giftCertificate );
                return(RedirectToAction("Index"));
            }

            ViewBag.Commodities    = _commodityService.GetAllCommodity().OrderBy(o => o.Name);
            ViewBag.CommodityTypes = _commodityTypeService.GetAllCommodityType().OrderBy(o => o.Name);

            ViewBag.DCurrencies       = _detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.CURRENCY).OrderBy(o => o.SortOrder);
            ViewBag.DFundSources      = _detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.FUND_SOURCE).OrderBy(o => o.SortOrder);
            ViewBag.DBudgetTypes      = _detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.BUDGET_TYPE).OrderBy(o => o.SortOrder);
            ViewBag.Donors            = new SelectList(_donorService.GetAllDonor().OrderBy(o => o.Name), "DonorID", "Name");
            ViewBag.Programs          = new SelectList(_programService.GetAllProgram(), "ProgramID", "Name");
            ViewBag.DModeOfTransports = new SelectList(_detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.TRANSPORT_MODE).OrderBy(o => o.SortOrder), "DetailID", "Name");

            //return the model with the values pre-populated
            return(Create()); //GiftCertificateViewModel.GiftCertificateModel(giftcertificate));
        }
        /// <summary>
        /// Gifts the certificate model.
        /// </summary>
        /// <param name="GiftCertificateModel">The gift certificate model.</param>
        /// <returns></returns>
        public static GiftCertificateViewModel GiftCertificateModel(GiftCertificate GiftCertificateModel)
        {
            GiftCertificateViewModel giftCertificateViewModel = new GiftCertificateViewModel();

            giftCertificateViewModel.GiftCertificateID = GiftCertificateModel.GiftCertificateID;
            giftCertificateViewModel.GiftDate = GiftCertificateModel.GiftDate;
            giftCertificateViewModel.DonorID = GiftCertificateModel.DonorID;
            giftCertificateViewModel.ShippingInstructionID = GiftCertificateModel.ShippingInstructionID;
            giftCertificateViewModel.ReferenceNo = GiftCertificateModel.ReferenceNo;
            giftCertificateViewModel.Vessel = GiftCertificateModel.Vessel;
            giftCertificateViewModel.ETA = GiftCertificateModel.ETA;
            giftCertificateViewModel.ProgramID = GiftCertificateModel.ProgramID;
            giftCertificateViewModel.PortName = GiftCertificateModel.PortName;
            giftCertificateViewModel.DModeOfTransport = GiftCertificateModel.DModeOfTransport;
            var giftCertificateDetail = GiftCertificateModel.GiftCertificateDetails.FirstOrDefault();
            if (giftCertificateDetail != null)
                giftCertificateViewModel.CommodityTypeID = giftCertificateDetail.Commodity.CommodityTypeID;
            else
                giftCertificateViewModel.CommodityTypeID = 1;//by default 'food'
            giftCertificateViewModel.GiftCertificateDetails =
               GiftCertificateDetailsViewModel.GenerateListOfGiftCertificateDetailsViewModel(
                   GiftCertificateModel.GiftCertificateDetails.ToList());

            return giftCertificateViewModel;
        }
        public ActionResult Edit(GiftCertificateViewModel giftcertificate)
        {
            //just incase the user meses with the the hidden GiftCertificateID field
            Cats.Models.Hubs.GiftCertificate giftcert = _giftCertificateService.FindById(giftcertificate.GiftCertificateID);

            if (ModelState.IsValid && giftcert != null)
            {

                Cats.Models.Hubs.GiftCertificate giftCertificateModel = giftcertificate.GenerateGiftCertificate();

                List<Cats.Models.Hubs.GiftCertificateDetailsViewModel> insertCommodities = GetSelectedGiftCertificateDetails(giftcertificate.JSONInsertedGiftCertificateDetails);
                List<Cats.Models.Hubs.GiftCertificateDetailsViewModel> deletedCommodities = GetSelectedGiftCertificateDetails(giftcertificate.JSONDeletedGiftCertificateDetails);
                List<Cats.Models.Hubs.GiftCertificateDetailsViewModel> updateCommodities = GetSelectedGiftCertificateDetails(giftcertificate.JSONUpdatedGiftCertificateDetails);

                _giftCertificateService.Update(giftCertificateModel, GenerateGiftCertificate(insertCommodities),
                     GenerateGiftCertificate(updateCommodities),
                     GenerateGiftCertificate(deletedCommodities));

                return RedirectToAction("Index");
            }
            ViewBag.Commodities = _commodityService.GetAllCommodity().OrderBy(o => o.Name);

            ViewBag.DCurrencies = _detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.CURRENCY).OrderBy(o => o.SortOrder);
            ViewBag.DFundSources = _detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.FUND_SOURCE).OrderBy(o => o.SortOrder);
            ViewBag.DBudgetTypes = _detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.BUDGET_TYPE).OrderBy(o => o.SortOrder);

            ViewBag.CommodityTypes = new SelectList(_commodityTypeService.GetAllCommodityType().OrderBy(o => o.Name), "CommodityTypeID", "Name", giftcert.GiftCertificateDetails.FirstOrDefault().Commodity.CommodityTypeID);
            ViewBag.Donors = new SelectList(_donorService.GetAllDonor().OrderBy(o => o.Name), "DonorID", "Name", giftcertificate.DonorID);
            ViewBag.Programs = new SelectList(_programService.GetAllProgram(), "ProgramID", "Name", giftcertificate.ProgramID);
            ViewBag.DModeOfTransports = new SelectList(_detailService.GetAllDetail().Where(d => d.MasterID == Master.Constants.TRANSPORT_MODE).OrderBy(o => o.SortOrder), "DetailID", "Name", giftcertificate.DModeOfTransport);
            return View(giftcertificate);
        }