Exemple #1
0
        public int DelBinding(Base_DataBindViewModel base_DataBindViewModel)
        {
            int[] needDelId = GetBindId(base_DataBindViewModel);
            int   f         = 0;

            if (needDelId != null && needDelId.Length > 0)
            {
                LessonBLL lsnBll = new LessonBLL();

                for (int i = 0; i < needDelId.Length; i++)
                {
                    //check there is lesson binded.
                    if (!lsnBll.ExistByFk(needDelId[i]))
                    {
                        using (_db = new ApplicationDbContext())
                        {
                            var m = _db.Base_DataBind.Find(needDelId[i]);
                            if (m != null)
                            {
                                _db.Entry(m).State = EntityState.Deleted;
                                f += _db.SaveChanges();
                            }
                        }
                    }
                }
            }

            return(f);
        }
Exemple #2
0
        /// <summary>
        /// get binded id that will be deleted.
        /// </summary>
        /// <param name="mdl"></param>
        /// <returns></returns>
        private int[] GetBindId(Base_DataBindViewModel mdl)
        {
            List <int> result = new List <int>();

            if (mdl.GenreId.Count == 0)
            {
                return(null);
            }

            var bind    = new Base_DataBind();
            var bindBLL = new Base_DataBindBLL();

            foreach (var i in mdl.GenreId)
            {
                bind = new Base_DataBind
                {
                    GenreId   = i,
                    GradeId   = mdl.GradeId,
                    PeriodId  = mdl.PeriodId,
                    SchoolId  = mdl.SchoolId,
                    SubjectId = mdl.SubjectId
                };

                string whr = bindBLL.ArrayToWhere(bind);

                var id = bindBLL.GetBindingId("1=1 " + whr);

                if (id != null)
                {
                    result.Add(int.Parse(id));
                }
            }

            return(result.ToArray());
        }
Exemple #3
0
        public int SaveBindingData(Base_DataBindViewModel dbModel)
        {
            var bdBindBll = new Base_DataBindBLL();
            List <Base_DataBind> dbList = new List <Base_DataBind>();

            if (dbModel.GenreId.Count() > 0)
            {
                foreach (string i in dbModel.GenreId)
                {
                    var mdl = new Base_DataBind
                    {
                        GenreId   = i,
                        GradeId   = dbModel.GradeId,
                        PeriodId  = dbModel.PeriodId,
                        SchoolId  = dbModel.SchoolId,
                        SubjectId = dbModel.SubjectId
                    };

                    //check if data exists
                    string whr   = bdBindBll.ArrayToWhere(mdl);
                    bool   exist = bdBindBll.GetBindingId("1=1 " + whr) != null;

                    if (!exist)   //not exists
                    {
                        dbList.Add(mdl);
                    }
                }
                if (dbList.Count > 0)
                {
                    return(SaveBindingModels(dbList));
                }
            }

            return(0);
        }
Exemple #4
0
        public ActionResult delBinding(string[] clickedId, string[] upperIds)
        {
            int    s     = 0;//record count deled.
            string error = string.Empty;

            if (clickedId.Length > 0 && upperIds.Length == 3)
            {
                Base_DataBindViewModel baseBinding = new Base_DataBindViewModel
                {
                    PeriodId  = upperIds[0],
                    GradeId   = upperIds[1],
                    SubjectId = upperIds[2],
                    SchoolId  = 1.ToString(),
                    GenreId   = clickedId
                };
                s = this.delBinding(baseBinding);
            }
            else
            {
                error = "parameters error";
            }

            return(Json(new { t = s, msg = error }, JsonRequestBehavior.AllowGet));
        }
Exemple #5
0
        /// <summary>
        /// count record deleted.
        /// </summary>
        /// <param name="bindingModel"></param>
        /// <returns></returns>
        private int delBinding(Base_DataBindViewModel bindingModel)
        {
            int svd = trainBaseSv.DelBinding(bindingModel);

            return(svd);
        }
Exemple #6
0
        /// <summary>
        /// ajax update and add new relation of databinding of the school.
        /// </summary>
        public ActionResult saveBinding(Base_DataBindViewModel bindingModel)
        {
            int i = trainBaseSv.SaveBindingData(bindingModel);

            return(Json(new { i }, JsonRequestBehavior.AllowGet));
        }