public ActionResult GetAppropSourceForm(int ActionID, int PrimaryID)
        {
            AppropSourceModel model = new AppropSourceModel();

            if (ActionID == 2)
            {
                var appropSource = (from a in BOSSDB.Tbl_FMApprop_AppropriationSource where a.AppropriationID == PrimaryID select a).FirstOrDefault();

                model.FundSourceID                     = Convert.ToInt32(appropSource.FundSourceID);
                model.AppropSourceTypeID               = Convert.ToInt32(appropSource.Tbl_FMApprop_FundSource.AppropSourceTypeID);
                model.AppropSourceList.Description     = appropSource.Description;
                model.BudgetYearID                     = Convert.ToInt32(appropSource.BudgetYearID);
                model.AppropSourceList.AppropriationID = appropSource.AppropriationID;

                var fundsourceTBL = (from a in BOSSDB.Tbl_FMApprop_FundSource orderby a.FundSourceTitle where a.AppropSourceTypeID == model.AppropSourceTypeID select a).ToList();

                if (fundsourceTBL.Count > 0)
                {
                    model.FundSourceList = new SelectList(fundsourceTBL, "FundSourceID", "FundSourceTitle");
                }
            }
            else
            {
                var appropSourceTypeTBL = (from a in BOSSDB.FMApprop_AppropriationSourceType orderby a.AppropSourceTypeTitle select a.AppropSourceTypeID).FirstOrDefault();
                var fundsourceTBL       = (from a in BOSSDB.Tbl_FMApprop_FundSource orderby a.FundSourceTitle where a.AppropSourceTypeID == appropSourceTypeTBL select a).ToList();
                if (fundsourceTBL.Count > 0)
                {
                    model.FundSourceList = new SelectList(fundsourceTBL, "FundSourceID", "FundSourceTitle");
                }
            }
            model.FundSourceList = (from li in model.FundSourceList orderby li.Text select li).ToList();

            model.ActionID = ActionID;
            return(PartialView("AppropriationSource/_AppropSourceForm", model));
        }
        //=============================================================================================================================
        //Apprpriation Source Tab
        //=============================================================================================================================
        //Get Appropriation Source Datatable Partial View
        public ActionResult GetAppropSourceDTable()
        {
            AppropSourceModel model = new AppropSourceModel();

            List <AppropSourceList> getAppropSourceList = new List <AppropSourceList>();

            var SQLQuery = "SELECT [AppropriationID], [AppropSourceTypeTitle], [FundSourceTitle], [Description], [BudgetYearTitle] FROM [Tbl_FMApprop_AppropriationSource], [Tbl_FMApprop_FundSource], [FMApprop_AppropriationSourceType], [FMApprop_BudgetYear] where [FMApprop_BudgetYear].BudgetYearID = [dbo].Tbl_FMApprop_AppropriationSource.BudgetYearID and [Tbl_FMApprop_AppropriationSource].FundSourceID = [Tbl_FMApprop_FundSource].FundSourceID and [Tbl_FMApprop_FundSource].AppropSourceTypeID = [FMApprop_AppropriationSourceType].AppropSourceTypeID";

            using (SqlConnection Connection = new SqlConnection(GlobalFunction.ReturnConnectionString()))
            {
                Connection.Open();
                using (SqlCommand command = new SqlCommand("[dbo].[SP_AppropriationSource]", Connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add(new SqlParameter("@SQLStatement", SQLQuery));
                    SqlDataReader dr = command.ExecuteReader();
                    while (dr.Read())
                    {
                        getAppropSourceList.Add(new AppropSourceList()
                        {
                            AppropriationID       = GlobalFunction.ReturnEmptyInt(dr[0]),
                            AppropSourceTypeTitle = GlobalFunction.ReturnEmptyString(dr[1]),
                            FundSourceTitle       = GlobalFunction.ReturnEmptyString(dr[2]),
                            Description           = GlobalFunction.ReturnEmptyString(dr[3]),
                            BudgetYearTitle       = GlobalFunction.ReturnEmptyString(dr[4])
                        });
                    }
                }
                Connection.Close();
            }
            model.getAppropSourceList = getAppropSourceList.ToList();
            return(PartialView("AppropriationSource/_TableAppropriationSource", model.getAppropSourceList));
        }
        public ActionResult GetAppSourceTab()
        {
            AppropSourceModel model = new AppropSourceModel();

            return(PartialView("AppropriationSource/AppropriationSourceIndex", model));
        }
        public ActionResult SaveAppropSource(AppropSourceModel model)
        {
            var isExist = "";

            if (ModelState.IsValid)
            {
                var appropDesc = model.AppropSourceList.Description;
                appropDesc = Regex.Replace(appropDesc, @"\s\s+", "");
                appropDesc = Regex.Replace(appropDesc, @"^\s+", "");
                appropDesc = Regex.Replace(appropDesc, @"\s+$", "");
                appropDesc = new CultureInfo("en-US").TextInfo.ToTitleCase(appropDesc);
                Tbl_FMApprop_AppropriationSource checkApprop = (from a in BOSSDB.Tbl_FMApprop_AppropriationSource where (a.Description == model.AppropSourceList.Description) select a).FirstOrDefault();

                if (model.ActionID == 1)
                {
                    if (checkApprop == null)
                    {
                        Tbl_FMApprop_AppropriationSource appropS = new Tbl_FMApprop_AppropriationSource();
                        appropS.Description  = appropDesc;
                        appropS.FundSourceID = model.FundSourceID;
                        appropS.BudgetYearID = model.BudgetYearID;
                        BOSSDB.Tbl_FMApprop_AppropriationSource.Add(appropS);
                        BOSSDB.SaveChanges();
                        isExist = "false";
                    }
                    else if (checkApprop != null)
                    {
                        isExist = "true";
                    }
                }
                else if (model.ActionID == 2)
                {
                    Tbl_FMApprop_AppropriationSource        approp            = (from a in BOSSDB.Tbl_FMApprop_AppropriationSource where a.AppropriationID == model.AppropSourceList.AppropriationID select a).FirstOrDefault();
                    List <Tbl_FMApprop_AppropriationSource> appropDescription = (from e in BOSSDB.Tbl_FMApprop_AppropriationSource where e.Description == appropDesc select e).ToList();
                    if (checkApprop != null)
                    {
                        if (approp.Description == appropDesc)
                        {
                            isExist = "justUpdate";
                        }
                        else
                        {
                            if (approp.Description != appropDesc && appropDescription.Count >= 1)
                            {
                                isExist = "true";
                            }
                            else
                            {
                                isExist = "justUpdate";
                            }
                        }
                    }
                    else if (checkApprop == null)
                    {
                        isExist = "justUpdate";
                    }
                    if (isExist == "justUpdate")
                    {
                        approp.Description  = appropDesc;
                        approp.FundSourceID = model.FundSourceID;
                        approp.BudgetYearID = model.BudgetYearID;
                        BOSSDB.Entry(approp);
                        BOSSDB.SaveChanges();
                    }
                }
            }
            return(new JsonResult()
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = new { isExist = isExist }
            });
        }
        public ActionResult onChangeFundSource(AppropSourceModel model, int AppropSourceTypeID)
        {
            var FoundSourceClass = (from a in BOSSDB.Tbl_FMApprop_FundSource where a.AppropSourceTypeID == AppropSourceTypeID select a).ToList();

            return(Json(new SelectList(FoundSourceClass, "FundSourceID", "FundSourceTitle"), JsonRequestBehavior.AllowGet));
        }
        public ActionResult FileAppropFundSource()
        {
            AppropSourceModel model = new AppropSourceModel();

            return(View());
        }