public bool CreateFunding(FundingDetail fund)
 {
     try
     {
         _db.FundingDetails.InsertOnSubmit(fund);
         _db.SubmitChanges();
         return true;
     }
     catch
     {
         return false;
     }
 }
 partial void DeleteFundingDetail(FundingDetail instance);
 partial void UpdateFundingDetail(FundingDetail instance);
 partial void InsertFundingDetail(FundingDetail instance);
		private void detach_FundingDetails(FundingDetail entity)
		{
			this.SendPropertyChanging();
			entity.Contact = null;
		}
        public ActionResult Amend(int id, int? LeadContactID, int? StagedPayment, int? ProgrammeID, int? ExtendYear, 
            int? ExtendMonth, int? LimitedYear, int? LimitedMonth, FormCollection collection)
        {
            CultureInfo enUS = new CultureInfo("en-US");
            var ser = _db.GetService(id);
            ser.SerName = collection["ServiceName"];
            ser.SerIsActive = 1;
            ser.SerShortDescription = collection["ShortDescription"];
            ser.SerFullDescription = collection["FullDescription"];
            ser.SerSubType = collection["SubType"];
            ser.SerDeptCode = collection["DeptCode"];
            ser.LeadContactID = LeadContactID;
            ser.SerType = collection["SerType"];
            ser.ClientDescription = collection["ClientDescription"];
            ser.SerDescriptionDelivery = collection["DescriptionDelivery"];
            ser.SerAttendance = collection["Attendance"];
            ser.SerContractCode = collection["ContractCode"];
            ser.SerStartExpected = _db.ConvertDate(collection["StartExpected"], "dd/MM/yyyy");
            ser.SerContractValue = collection["ContractValue"];
            ser.SerStartDate = _db.ConvertDate(collection["StartDate"], "dd/MM/yyyy");
            ser.SerEndDate = _db.ConvertDate(collection["EndDate"], "dd/MM/yyyy");
            ser.SerReferralProcess = collection["ReferralProcess"];

            ser.SerStagedPayment = StagedPayment;
            ser.SerExtendable = (collection["Extendable"] == "1" ? 1 : 0);
            ser.SerTimeLimited = (collection["TimeLimited"] == "1" ? 1 : 0);
            ser.SerExtendYear = ser.SerExtendable == 1 ? ExtendYear : 0;
            ser.SerExtendMonth = ser.SerExtendable == 1 ? ExtendMonth : 0;
            ser.SerTimeLimitedYear = ser.SerTimeLimited == 1 ? LimitedYear : 0;
            ser.SerTimeLimitedMonth = ser.SerTimeLimited == 1 ? LimitedMonth : 0;
            ser.ProgrammeID = ProgrammeID;
            ser.OtherService = "," + collection["OtherService[]"] + ",";
            ser.SerDetail3RefList = "," + collection["SerDetail3RefList[]"] + ",";
            ser.SerDetail2RefList = ","+collection["ServiceDetail2[]"]+",";

            if (ser.SerSubType == "Contract")
            {
                ser.SerContractRefList = "," + collection["ServiceContract[]"]+",";
            }

            if (ser.SerSubType == "Funded")
            {
                var fund = _db.GetFunding(id);
                var isNewFunding = false;
                if (fund == null)
                {
                    fund = new FundingDetail();
                    isNewFunding = true;
                }
                fund.FundingSource = collection["fundingsource"];
                fund.FundingNeeds = collection["fundingneeds"];
                fund.FundingContractDetail = Convert.ToInt32(collection["FundingContactID"]);
                fund.FundingContinuationNeeded = collection["fundingcontinuation"] == "1" ? 1 : 0;
                if (fund.FundingContinuationNeeded == 1)
                {
                    fund.FundingContinuationAmount = Convert.ToDecimal(collection["continuationamount"]);
                    fund.FundingContinuationDetail = collection["continuationdetail"];
                }

                fund.FundingAmount = Convert.ToDecimal(collection["fundingamount"]);
                fund.FundingStart = _db.ConvertDate(collection["fundingstart"], "dd/MM/yyyy");
                fund.FundingEnd = _db.ConvertDate(collection["fundingend"], "dd/MM/yyyy");
                fund.FundraisingForText = collection["fundraisingtext"];
                fund.FundraisingNeeds = collection["fundraisingneeds"];
                fund.FundraisingRequiredBy = _db.ConvertDate(collection["fundingrequiredby"], "dd/MM/yyyy");
                fund.FundraisingWhy = collection["fundingfundraisingwhy"];
                fund.FundraisingComplete = collection["fundingcomplete"] == "1" ? 1 : 0;
                fund.FundraisingCompletedDate = fund.FundraisingComplete == 1 ? _db.ConvertDate(collection["fundingcompletedate"], "dd/MM/yyyy") : null;
                fund.FundraisingDonorAnonymous = collection["donoranonymous"] == "1" ? 1 : 0;
                fund.FundraisingDonationDate = _db.ConvertDate(collection["donationdate"], "dd/MM/yyyy");
                fund.FundraisingDonorAmount = collection["donoramount"]==""? new decimal?():Convert.ToDecimal(collection["donoramount"]);
                fund.FundraisingDonationIncremental = collection["fundingincremental"]=="1"? 1:0;
                fund.SerID = ser.SerID;
                if (isNewFunding == true)
                    _db.CreateFunding(fund);
            }
            _db.Update();
            //ViewBag.testCheckList = collection["ServiceContract[]"];
            //ViewBag.testCheck = collection["fundingcomplete"];
            //ViewBag.testDate = collection["StartExpected"];
            //ViewBag.testMoney = collection["fundingamount"];

            //ViewBag.RefFrom = "ServiceDetail2";
            //ViewBag.RefChecked = ",44,45,47";
            //ViewBag.RefFrom = "ServiceContract";
            //ViewBag.RefChecked = ",31,32,40";
            //RedirectToAction("Add","Service");
            ViewBag.Alert = "true";
            ViewBag.Message = "Action success!";
            ViewBag.URL = "/Service/List";

            return View("../Shared/Redirect");
            //return RedirectToAction("List");
        }