public static GiftCertificate BindGiftCertificate(GiftCertificate giftCertificate, GiftCertificateViewModel giftCertificateViewModel)
        {
            giftCertificate.GiftCertificateID = giftCertificateViewModel.GiftCertificateID;
            giftCertificate.GiftDate = giftCertificateViewModel.GiftDate;
               // giftCertificate.SINumber = giftCertificateViewModel.SINumber;
            giftCertificate.DonorID = giftCertificateViewModel.DonorID;
            giftCertificate.ReferenceNo = giftCertificateViewModel.ReferenceNo;
            giftCertificate.Vessel = giftCertificateViewModel.Vessel;
            giftCertificate.ETA = giftCertificateViewModel.ETA;
            giftCertificate.IsPrinted = giftCertificateViewModel.IsPrinted;
            giftCertificate.DModeOfTransport = giftCertificateViewModel.DModeOfTransport;
            giftCertificate.ProgramID = giftCertificateViewModel.ProgramID;
            giftCertificate.PortName = giftCertificateViewModel.PortName;
            giftCertificate.DeclarationNumber = giftCertificateViewModel.DeclarationNumber;

            return giftCertificate;
        }
        public ActionResult Create(GiftCertificateViewModel giftcertificateViewModel)
        {
            if (ModelState.IsValid && giftcertificateViewModel != null)
            {
                var giftCertificate = GiftCertificateViewModelBinder.BindGiftCertificate(giftcertificateViewModel);
                giftCertificate.StatusID = 1;
                var shippingInstructionID = _shippingInstructionService.GetSiNumber(giftcertificateViewModel.SINumber).ShippingInstructionID;
                giftCertificate.ShippingInstructionID = shippingInstructionID;
                _giftCertificateService.AddGiftCertificate(giftCertificate);
                return RedirectToAction("Edit", new { id=giftCertificate.GiftCertificateID});
            }

            PopulateLookup();

            return Create(); //GiftCertificateViewModel.GiftCertificateModel(giftcertificate));
        }
 public ActionResult Create()
 {
     PopulateLookup();
     var gift = new GiftCertificateViewModel();
     gift.GiftDate = DateTime.Today;
     gift.ETA = DateTime.Today;
     gift.CommodityTypeID = 1;
     return View();
 }
        public ActionResult Edit(GiftCertificateViewModel giftcertificate)
        {
            //just incase the user meses with the the hidden GiftCertificateID field
            var giftcert = _giftCertificateService.FindById(giftcertificate.GiftCertificateID);

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

                giftcert = GiftCertificateViewModelBinder.BindGiftCertificate(giftcert, giftcertificate);

                _giftCertificateService.EditGiftCertificate(giftcert);

                return RedirectToAction("Index");
            }
            PopulateLookup(false, giftcert);

            return View(giftcertificate);
        }
        public static GiftCertificateViewModel BindGiftCertificateViewModel(GiftCertificate giftCertificateModel, string userPrefrence, bool bindWithDetail = false)
        {
            var giftCertificateViewModel = new GiftCertificateViewModel();

            giftCertificateViewModel.GiftCertificateID = giftCertificateModel.GiftCertificateID;
            giftCertificateViewModel.GiftDate = giftCertificateModel.GiftDate;
            giftCertificateViewModel.DonorID = giftCertificateModel.DonorID;
            giftCertificateViewModel.SINumber = giftCertificateModel.ShippingInstruction.Value;
            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.Donor = giftCertificateModel.Donor.Name;
            giftCertificateViewModel.StatusID = giftCertificateModel.StatusID;
            giftCertificateViewModel.DeclarationNumber = giftCertificateModel.DeclarationNumber;
            giftCertificateViewModel.GiftDatePref=giftCertificateModel.GiftDate.ToCTSPreferedDateFormat(userPrefrence);

            var giftCertificateDetail = giftCertificateModel.GiftCertificateDetails.FirstOrDefault();
            if (giftCertificateDetail != null)
                giftCertificateViewModel.CommodityTypeID = giftCertificateDetail.Commodity.CommodityTypeID;
            else
                giftCertificateViewModel.CommodityTypeID = 1;//by default 'food'
            if (bindWithDetail)
            {
                giftCertificateViewModel.GiftCertificateDetails =
                     BindListOfGiftCertificateDetailsViewModel(
                         giftCertificateModel.GiftCertificateDetails.ToList());
            }

            return giftCertificateViewModel;
        }
 public static GiftCertificate BindGiftCertificate(GiftCertificateViewModel giftCertificateViewModel)
 {
     return BindGiftCertificate(new GiftCertificate(), giftCertificateViewModel);
 }