예제 #1
0
        public IActionResult Create(Tablelist context, int groups)
        {
            var TablelistTablegroups = new Tablelistgroup();


            if (!string.IsNullOrEmpty(context.TaskName))
            {
                db.TablelistSet.Add(context);
                db.SaveChanges();
                // сохраняем в бд все изменения
            }
            if (groups != 0)
            {
                if (context.Id == 0)
                {
                    context = db.TablelistSet.Last();
                }

                TablelistTablegroups.TablelistId  = context.Id;
                TablelistTablegroups.TablegroupId = groups;
                db.TablelistTablegroup.Add(TablelistTablegroups);
                db.SaveChanges();
            }
            return(RedirectToAction("index"));
        }
예제 #2
0
        public IActionResult Ccreate(Tablelist context, int cgroups, int cid)
        {
            var TablelistTablegroups = new Tablelistgroup();



            if (context.Id == 0)
            {
                context = db.TablelistSet.Last();
            }

            TablelistTablegroups.TablelistId  = cid;
            TablelistTablegroups.TablegroupId = cgroups;
            db.TablelistTablegroup.Add(TablelistTablegroups);
            db.SaveChanges();

            return(RedirectToAction("index"));
        }
예제 #3
0
        public IActionResult Addgroup()
        {
            List <int> listidgroup = new List <int>();

            foreach (var model in db.TablegroupSet.ToList())
            {
                listidgroup.Add(model.Id);
            }
            List <int> listidtask = new List <int>();

            foreach (var model in db.TablelistSet.ToList())
            {
                listidtask.Add(model.Id);
            }
            int id(int max)
            {
                Random number = new Random();
                int    i      = number.Next(0, max);

                return(i);
            }

            Tablelistgroup Tablelistgroup;

            void newTablelistgroup()
            {
                Tablelistgroup = new Tablelistgroup {
                    TablegroupId = listidgroup[id(listidgroup.Count)], TablelistId = listidtask[id(listidtask.Count)]
                };
            }

            newTablelistgroup();


            List <int[]> getlistgroup = new List <int[]>();

            foreach (var model in db.TablelistTablegroup.ToList())
            {
                getlistgroup.Add(new int[] { model.TablelistId, model.TablegroupId });
            }
            bool ok = false;

            while (!ok)
            {
                for (int i = 0; i < getlistgroup.Count; i++)
                {
                    int i0 = getlistgroup[i][0];
                    int i1 = getlistgroup[i][1];
                    if (Tablelistgroup.TablelistId == i0 && Tablelistgroup.TablegroupId == i1)
                    {
                        ok = false;
                        newTablelistgroup();
                        break;
                    }
                    else
                    {
                        ok = true;
                    }
                }
            }
            if (ok)
            {
                db.TablelistTablegroup.Add(Tablelistgroup);
                db.SaveChanges();
            }


            return(RedirectToAction("Index"));
        }