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

            giftCertificateViewModel.GiftCertificateID = GiftCertificateModel.GiftCertificateID;
            giftCertificateViewModel.GiftDate          = GiftCertificateModel.GiftDate;
            giftCertificateViewModel.DonorID           = GiftCertificateModel.DonorID;
            giftCertificateViewModel.SINumber          = GiftCertificateModel.SINumber;
            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
        public static Models.GiftCertificateViewModel GiftCertificateModel(BLL.GiftCertificate GiftCertificateModel)
        {
            GiftCertificateViewModel giftCertificateViewModel = new GiftCertificateViewModel();

            giftCertificateViewModel.GiftCertificateID = GiftCertificateModel.GiftCertificateID;
            giftCertificateViewModel.GiftDate          = GiftCertificateModel.GiftDate;
            giftCertificateViewModel.DonorID           = GiftCertificateModel.DonorID;
            giftCertificateViewModel.SINumber          = GiftCertificateModel.SINumber;
            giftCertificateViewModel.ReferenceNo       = GiftCertificateModel.ReferenceNo;
            giftCertificateViewModel.Vessel            = GiftCertificateModel.Vessel;
            giftCertificateViewModel.ETA                    = GiftCertificateModel.ETA;
            giftCertificateViewModel.ProgramID              = GiftCertificateModel.ProgramID;
            giftCertificateViewModel.PortName               = GiftCertificateModel.PortName;
            giftCertificateViewModel.DModeOfTransport       = GiftCertificateModel.DModeOfTransport;
            giftCertificateViewModel.GiftCertificateDetails =
                GiftCertificateDetailsViewModel.GenerateListOfGiftCertificateDetailsViewModel(
                    GiftCertificateModel.GiftCertificateDetails);

            return(giftCertificateViewModel);
        }
        public ActionResult Create(GiftCertificateViewModel giftcertificate)
        {
            if (ModelState.IsValid)
            {
                BLL.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 == BLL.Master.Constants.CURRENCY).OrderBy(o => o.SortOrder);
            ViewBag.DFundSources = _detailService.GetAllDetail().Where(d => d.MasterID == BLL.Master.Constants.FUND_SOURCE).OrderBy(o => o.SortOrder);
            ViewBag.DBudgetTypes = _detailService.GetAllDetail().Where(d => d.MasterID == BLL.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 == BLL.Master.Constants.TRANSPORT_MODE).OrderBy(o => o.SortOrder), "DetailID", "Name");

            //return the model with the values pre-populated
            return Create(); //GiftCertificateViewModel.GiftCertificateModel(giftcertificate));
        }
 private void InsertGiftCertificate(GiftCertificateViewModel giftcertificate, GiftCertificate giftCertificateModel)
 {
     List<Models.GiftCertificateDetailsViewModel> giftCertificateDetails = GetSelectedGiftCertificateDetails(giftcertificate.JSONInsertedGiftCertificateDetails);
     var giftDetails = GenerateGiftCertificate(giftCertificateDetails);
     foreach (BLL.GiftCertificateDetail giftDetail in giftDetails)
     {
         giftCertificateModel.GiftCertificateDetails.Add(giftDetail);
     }
     _giftCertificateService.AddGiftCertificate(giftCertificateModel);
 }
        public ActionResult Edit(GiftCertificateViewModel giftcertificate)
        {
            //just incase the user meses with the the hidden GiftCertificateID field
            GiftCertificate giftcert = _giftCertificateService.FindById(giftcertificate.GiftCertificateID);

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

                GiftCertificate giftCertificateModel = giftcertificate.GenerateGiftCertificate();

                List<Models.GiftCertificateDetailsViewModel> insertCommodities = GetSelectedGiftCertificateDetails(giftcertificate.JSONInsertedGiftCertificateDetails);
                List<Models.GiftCertificateDetailsViewModel> deletedCommodities = GetSelectedGiftCertificateDetails(giftcertificate.JSONDeletedGiftCertificateDetails);
                List<Models.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 == BLL.Master.Constants.CURRENCY).OrderBy(o => o.SortOrder);
            ViewBag.DFundSources = _detailService.GetAllDetail().Where(d => d.MasterID == BLL.Master.Constants.FUND_SOURCE).OrderBy(o => o.SortOrder);
            ViewBag.DBudgetTypes = _detailService.GetAllDetail().Where(d => d.MasterID == BLL.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 == BLL.Master.Constants.TRANSPORT_MODE).OrderBy(o => o.SortOrder), "DetailID", "Name", giftcertificate.DModeOfTransport);
            return View(giftcertificate);
        }
        /// <summary>
        /// Gifts the certificate model.
        /// </summary>
        /// <param name="GiftCertificateModel">The gift certificate model.</param>
        /// <returns></returns>
        public static Models.GiftCertificateViewModel GiftCertificateModel(BLL.GiftCertificate GiftCertificateModel)
        {
            GiftCertificateViewModel giftCertificateViewModel = new GiftCertificateViewModel();

            giftCertificateViewModel.GiftCertificateID = GiftCertificateModel.GiftCertificateID;
            giftCertificateViewModel.GiftDate = GiftCertificateModel.GiftDate;
            giftCertificateViewModel.DonorID = GiftCertificateModel.DonorID;
            giftCertificateViewModel.SINumber = GiftCertificateModel.SINumber;
            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 static Models.GiftCertificateViewModel GiftCertificateModel(BLL.GiftCertificate GiftCertificateModel)
        {
            GiftCertificateViewModel giftCertificateViewModel = new GiftCertificateViewModel();

            giftCertificateViewModel.GiftCertificateID = GiftCertificateModel.GiftCertificateID;
            giftCertificateViewModel.GiftDate = GiftCertificateModel.GiftDate;
            giftCertificateViewModel.DonorID = GiftCertificateModel.DonorID;
            giftCertificateViewModel.SINumber = GiftCertificateModel.SINumber;
            giftCertificateViewModel.ReferenceNo = GiftCertificateModel.ReferenceNo;
            giftCertificateViewModel.Vessel = GiftCertificateModel.Vessel;
            giftCertificateViewModel.ETA = GiftCertificateModel.ETA;
            giftCertificateViewModel.ProgramID = GiftCertificateModel.ProgramID;
            giftCertificateViewModel.PortName = GiftCertificateModel.PortName;
            giftCertificateViewModel.DModeOfTransport = GiftCertificateModel.DModeOfTransport;
            giftCertificateViewModel.GiftCertificateDetails =
                GiftCertificateDetailsViewModel.GenerateListOfGiftCertificateDetailsViewModel(
                    GiftCertificateModel.GiftCertificateDetails);

            return giftCertificateViewModel;
        }