コード例 #1
0
        public async Task <IActionResult> Post([FromBody] ElectiveGroupVM model)
        {
            using (var ctx = new RypDbContext())
            {
                using (var tran = ctx.Database.BeginTransaction())
                {
                    var electiveGroup = new ElectiveGroup();
                    electiveGroup.Name    = model.Name;
                    electiveGroup.Shifr   = model.Shifr;
                    electiveGroup.Credits = model.Credits;
                    electiveGroup.Pr      = model.Pr;
                    electiveGroup.UserId  = model.UserId;
                    electiveGroup.Date    = DateTime.Now.ToString();
                    electiveGroup.TypeId  = model.Type.Id;

                    ctx.ElectiveGroups.Add(electiveGroup);
                    ctx.SaveChanges();

                    foreach (var item in model.Subjects)
                    {
                        var t = new SubjectElectiveGroup {
                            ElectiveGroupId = electiveGroup.Id, SubjectId = item.Id
                        };
                        electiveGroup.SubjectElectiveGroups.Add(t);
                    }

                    await ctx.SaveChangesAsync();

                    tran.Commit();
                }
            }

            return(Ok());
        }
コード例 #2
0
        public async Task <IActionResult> Post([FromBody] RypVM model)
        {
            if (ModelState.IsValid)
            {
                using (var context = new RypDbContext())
                {
                    using (var tran = context.Database.BeginTransaction())
                    {
                        var ryp = await context.Ryps.FirstOrDefaultAsync(x => x.Id == model.Id);

                        ryp.FullCheck = 1;

                        await context.SaveChangesAsync();

                        var checkedRyp = new CheckedRyp();
                        checkedRyp.RypId         = model.Id;
                        checkedRyp.Year          = model.Year;
                        checkedRyp.Specialty     = model.Specialty;
                        checkedRyp.OperatorCheck = model.OperatorCheck;
                        checkedRyp.FullCheck     = model.FullCheck;
                        checkedRyp.UserId        = model.UserId;
                        checkedRyp.Date          = model.Date;
                        checkedRyp.UpdateDate    = model.UpdateDate;
                        checkedRyp.Semesters     = model.Semesters;
                        checkedRyp.isOpen        = 0;
                        await db.Create(checkedRyp);

                        tran.Commit();
                    }
                }
            }
            return(Ok());
        }
コード例 #3
0
        public IActionResult Put(int id, [FromBody] ElectiveGroupVM model)
        {
            using (var context = new RypDbContext())
            {
                var electiveGroup = context.ElectiveGroups.FirstOrDefault(x => x.Id == id);
                var subjects      = context.SubjectElectiveGroups.Where(x => x.ElectiveGroupId == electiveGroup.Id).ToList();
                electiveGroup.SubjectElectiveGroups = subjects;
                electiveGroup.Name       = model.Name;
                electiveGroup.Shifr      = model.Shifr;
                electiveGroup.Credits    = model.Credits;
                electiveGroup.Pr         = model.Pr;
                electiveGroup.UpdateDate = DateTime.Now.ToString();
                electiveGroup.TypeId     = model.Type.Id;

                for (int i = electiveGroup.SubjectElectiveGroups.Count; i > 0; i--)
                {
                    context.SubjectElectiveGroups.Remove(electiveGroup.SubjectElectiveGroups[i - 1]);
                }
                context.SaveChanges();
                electiveGroup.SubjectElectiveGroups = new List <SubjectElectiveGroup>();

                for (int i = 0; i < model.Subjects.Count; i++)
                {
                    electiveGroup.SubjectElectiveGroups.Add(new SubjectElectiveGroup {
                        ElectiveGroupId = electiveGroup.Id, SubjectId = model.Subjects[i].Id
                    });
                }

                context.SaveChanges();
            }
            return(Ok());
        }
コード例 #4
0
        public async Task <IActionResult> Post([FromBody] SubjectVM model)
        {
            using (var context = new RypDbContext())
            {
                var type = context.SubjectTypes.FirstOrDefault(x => x.Name == model.Type.Name);

                var subject = new Subject();
                subject.RelatedItems = new List <SubjectPrerequisiteSubject>();
                subject.Name         = model.Name;
                subject.Shifr        = model.Shifr;
                subject.Credits      = model.Credits;
                subject.Lec          = model.Lec;
                subject.Lab          = model.Lab;
                subject.Pr           = model.Pr;
                subject.UserId       = model.UserId;
                subject.Date         = DateTime.Now.ToString();
                subject.TypeId       = type.Id;

                for (int i = 0; i < model.Prerequisites.Count; i++)
                {
                    subject.RelatedItems.Add(new SubjectPrerequisiteSubject {
                        Primary = subject, RelatedId = model.Prerequisites[i].Id
                    });
                }
                //subject.Prerequisites = model.Prerequisites;
                //model.Prerequisites.ForEach(p =>{
                //    context.Attach(p);
                //});

                var result = await context.Subjects.AddAsync(subject);

                context.SaveChanges();
            }
            return(Ok());
        }
コード例 #5
0
        public IActionResult Put(int id, [FromBody] RypVM model)
        {
            using (var context = new RypDbContext())
            {
                using (var tran = context.Database.BeginTransaction())
                {
                    var ryp = context.Ryps.FirstOrDefault(x => x.Id == id);
                    ryp.Semesters  = context.Semesters.Where(x => x.RypId == ryp.Id).ToList();
                    ryp.UpdateDate = DateTime.Now.ToString();

                    for (int i = ryp.Semesters.Count; i > 0; i--)
                    {
                        ryp.Semesters[i - 1].SemesterSubjects       = context.SemesterSubjects.Where(x => x.SemesterId == ryp.Semesters[i - 1].Id).ToList();
                        ryp.Semesters[i - 1].SemesterElectiveGroups = context.SemesterElectiveGroups.Where(x => x.SemesterId == ryp.Semesters[i - 1].Id).ToList();
                        for (int j = ryp.Semesters[i - 1].SemesterSubjects.Count; j > 0; j--)
                        {
                            context.SemesterSubjects.Remove(ryp.Semesters[i - 1].SemesterSubjects[j - 1]);
                        }
                        for (int j = ryp.Semesters[i - 1].SemesterElectiveGroups.Count; j > 0; j--)
                        {
                            context.SemesterElectiveGroups.Remove(ryp.Semesters[i - 1].SemesterElectiveGroups[j - 1]);
                        }
                        context.Semesters.Remove(ryp.Semesters[i - 1]);
                    }
                    context.SaveChanges();
                    ryp.Semesters = new List <Semester>();

                    for (int i = 0; i < 8; i++)
                    {
                        var semester = new Semester();
                        semester.RypId = ryp.Id;
                        context.Semesters.Add(semester);
                        context.SaveChanges();
                        foreach (var subject in model.Semesters[i].Subjects)
                        {
                            var t = new SemesterSubject {
                                SubjectId = subject.Id, SemesterId = semester.Id
                            };
                            context.SemesterSubjects.Add(t);
                            semester.SemesterSubjects.Add(t);
                        }
                        foreach (var electiveGroup in model.Semesters[i].Electives)
                        {
                            var t = new SemesterElectiveGroup {
                                ElectiveGroupId = electiveGroup.Id, SemesterId = semester.Id
                            };
                            context.SemesterElectiveGroups.Add(t);
                            semester.SemesterElectiveGroups.Add(t);
                        }
                        ryp.Semesters.Add(semester);
                    }

                    context.SaveChanges();
                    tran.Commit();
                }
            }
            return(Ok());
        }
コード例 #6
0
        public IActionResult Get()
        {
            List <ElectiveGroupVM> result = new List <ElectiveGroupVM>();

            using (var ctx = new RypDbContext())
            {
                result = ctx.ElectiveGroups
                         .Include(x => x.SubjectElectiveGroups)
                         .Select(x => new ElectiveGroupVM
                {
                    Id         = x.Id,
                    Name       = x.Name,
                    Shifr      = x.Shifr,
                    Credits    = x.Credits,
                    Pr         = x.Pr,
                    UserId     = x.UserId,
                    Date       = x.Date,
                    UpdateDate = x.UpdateDate,
                    Type       = x.Type,
                    Deleted    = x.Deleted,
                    Subjects   = x.SubjectElectiveGroups.Select(y => new SubjectVM
                    {
                        Id            = y.Subject.Id,
                        Name          = y.Subject.Name,
                        Shifr         = y.Subject.Shifr,
                        Credits       = y.Subject.Credits,
                        Lec           = y.Subject.Lec,
                        Lab           = y.Subject.Lab,
                        Pr            = y.Subject.Pr,
                        UserId        = y.Subject.UserId,
                        Date          = y.Subject.Date,
                        UpdateDate    = y.Subject.UpdateDate,
                        Type          = y.Subject.Type,
                        Prerequisites = y.Subject.RelatedItems.Select(z => new SubjectVM
                        {
                            Id         = z.RelatedId,
                            Name       = z.Related.Name,
                            Shifr      = z.Related.Shifr,
                            Credits    = z.Related.Credits,
                            Lec        = z.Related.Lec,
                            Lab        = z.Related.Lab,
                            Pr         = z.Related.Pr,
                            UserId     = z.Related.UserId,
                            Date       = z.Related.Date,
                            UpdateDate = z.Related.UpdateDate,
                            Type       = z.Related.Type
                        }).ToList()
                    }).ToList()
                }).Where(x => x.Deleted == 0).ToList();
            }

            return(Ok(result));
        }
コード例 #7
0
        public IActionResult Put(int id, [FromBody] SpecialtyVM model)
        {
            using (var context = new RypDbContext())
            {
                var specialty = context.Specialties.FirstOrDefault(x => x.Id == id);
                specialty.Name       = model.Name;
                specialty.Shifr      = model.Shifr;
                specialty.UpdateDate = DateTime.Now.ToString();

                context.SaveChanges();
            }
            return(Ok());
        }
コード例 #8
0
        public IActionResult Post([FromBody] RypVM model)
        {
            using (var ctx = new RypDbContext())
            {
                using (var tran = ctx.Database.BeginTransaction())
                {
                    var ryp = new Ryp();
                    ryp.Name        = model.Name;
                    ryp.Year        = model.Year;
                    ryp.UserId      = model.UserId;
                    ryp.SpecialtyId = model.Specialty.Id;
                    ryp.Date        = DateTime.Now.ToString();
                    ryp.Prototype   = model.Prototype;

                    ctx.Ryps.Add(ryp);
                    ctx.SaveChanges();

                    for (int i = 0; i < 8; i++)
                    {
                        var semester = new Semester();
                        semester.RypId = ryp.Id;
                        ctx.Semesters.Add(semester);
                        ctx.SaveChanges();
                        foreach (var subject in model.Semesters[i].Subjects)
                        {
                            var t = new SemesterSubject {
                                SubjectId = subject.Id, SemesterId = semester.Id
                            };
                            ctx.SemesterSubjects.Add(t);
                            semester.SemesterSubjects.Add(t);
                        }
                        foreach (var electiveGroup in model.Semesters[i].Electives)
                        {
                            var t = new SemesterElectiveGroup {
                                ElectiveGroupId = electiveGroup.Id, SemesterId = semester.Id
                            };
                            ctx.SemesterElectiveGroups.Add(t);
                            semester.SemesterElectiveGroups.Add(t);
                        }
                        ryp.Semesters.Add(semester);
                    }
                    ctx.SaveChanges();
                    tran.Commit();
                }
            }


            return(Ok());
        }
コード例 #9
0
        public IActionResult Put(int id, [FromBody] RypVM model)
        {
            using (var context = new RypDbContext())
            {
                using (var tran = context.Database.BeginTransaction())
                {
                    var ryp = context.Ryps.FirstOrDefault(x => x.Id == id);
                    ryp.OperatorCheck = 0;

                    context.SaveChanges();
                    tran.Commit();
                }
            }
            return(Ok());
        }
コード例 #10
0
        public async Task <IActionResult> Delete(int id)
        {
            using (var context = new RypDbContext())
            {
                using (var tran = context.Database.BeginTransaction())
                {
                    var ryp = await context.Ryps.FirstOrDefaultAsync(x => x.Id == id);

                    ryp.Deleted = 1;
                    await context.SaveChangesAsync();

                    tran.Commit();
                }
            }
            return(Ok());
        }
コード例 #11
0
        public async Task <IActionResult> Post([FromBody] SpecialtyVM model)
        {
            var specialty = new Specialty();

            using (var context = new RypDbContext())
            {
                specialty.Name   = model.Name;
                specialty.Shifr  = model.Shifr;
                specialty.UserId = model.UserId;
                specialty.Date   = DateTime.Now.ToString();

                var result = await context.Specialties.AddAsync(specialty);

                context.SaveChanges();
            }
            return(Ok());
        }
コード例 #12
0
        public async Task <IActionResult> Put(int id, [FromBody] CheckedRyp model)
        {
            using (var context = new RypDbContext())
            {
                var ryp = await context.Ryps.FirstOrDefaultAsync(x => x.Id == id);

                ryp.FullCheck = 0;

                await context.SaveChangesAsync();

                var checkedRyp = await db.GetRyp(model.Id);

                checkedRyp.isOpen = 1;
                await db.Update(checkedRyp);
            }
            return(Ok());
        }
コード例 #13
0
        public IActionResult Get()
        {
            List <Specialty> result = null;

            using (var ctx = new RypDbContext())
            {
                result = ctx.Specialties.Select(x => new Specialty
                {
                    Id         = x.Id,
                    Name       = x.Name,
                    Shifr      = x.Shifr,
                    UserId     = x.UserId,
                    Date       = x.Date,
                    UpdateDate = x.UpdateDate,
                    Deleted    = x.Deleted
                }).Where(x => x.Deleted == 0).ToList();
            }
            return(Ok(result));
        }
コード例 #14
0
        public IActionResult Get()
        {
            List <SubjectVM> result = null;

            using (var ctx = new RypDbContext())
            {
                result = ctx.Subjects.Select(x => new SubjectVM
                {
                    Id            = x.Id,
                    Name          = x.Name,
                    Shifr         = x.Shifr,
                    Credits       = x.Credits,
                    Lec           = x.Lec,
                    Lab           = x.Lab,
                    Pr            = x.Pr,
                    UserId        = x.UserId,
                    Date          = x.Date,
                    UpdateDate    = x.UpdateDate,
                    Type          = x.Type,
                    Deleted       = x.Deleted,
                    Prerequisites = x.RelatedItems.Select(y => new SubjectVM
                    {
                        Id         = y.Related.Id,
                        Name       = y.Related.Name,
                        Shifr      = y.Related.Shifr,
                        Credits    = y.Related.Credits,
                        Lec        = y.Related.Lec,
                        Lab        = y.Related.Lab,
                        Pr         = y.Related.Pr,
                        UserId     = y.Related.UserId,
                        Date       = y.Related.Date,
                        UpdateDate = y.Related.UpdateDate,
                        Type       = y.Related.Type
                    }).ToList()
                }).Where(x => x.Deleted == 0).ToList();
            }

            return(Ok(result));
        }
コード例 #15
0
        public IActionResult Put(int id, [FromBody] SubjectVM model)
        {
            using (var context = new RypDbContext())
            {
                var type = context.SubjectTypes.FirstOrDefault(x => x.Name == model.Type.Name);

                var subject       = context.Subjects.FirstOrDefault(x => x.Id == id);
                var prerequisites = context.SubjectPrerequisiteSubjects.Where(x => x.PrimaryId == subject.Id).ToList();
                subject.RelatedItems = prerequisites;
                subject.Name         = model.Name;
                subject.Shifr        = model.Shifr;
                subject.Credits      = model.Credits;
                subject.Lec          = model.Lec;
                subject.Lab          = model.Lab;
                subject.Pr           = model.Pr;
                subject.UpdateDate   = DateTime.Now.ToString();
                subject.TypeId       = type.Id;

                for (int i = subject.RelatedItems.Count; i > 0; i--)
                {
                    //subject.RelatedItems.Remove(subject.RelatedItems[i - 1]);
                    context.SubjectPrerequisiteSubjects.Remove(subject.RelatedItems[i - 1]);
                }
                context.SaveChanges();
                subject.RelatedItems = new List <SubjectPrerequisiteSubject>();

                for (int i = 0; i < model.Prerequisites.Count; i++)
                {
                    subject.RelatedItems.Add(new SubjectPrerequisiteSubject {
                        Primary = subject, RelatedId = model.Prerequisites[i].Id
                    });
                }

                context.SaveChanges();
            }

            return(Ok());
        }
コード例 #16
0
 public SpecialtysController()
 {
     _context = new RypDbContext();
 }
コード例 #17
0
        public async Task <IActionResult> Get()
        {
            List <RypVM> result = new List <RypVM>();

            using (var ctx = new RypDbContext())
            {
                result = await ctx.Ryps.Select(x => new RypVM
                {
                    Id            = x.Id,
                    Name          = x.Name,
                    UserId        = x.UserId,
                    Date          = x.Date,
                    UpdateDate    = x.UpdateDate,
                    Specialty     = x.Specialty,
                    Year          = x.Year,
                    OperatorCheck = x.OperatorCheck,
                    FullCheck     = x.FullCheck,
                    Deleted       = x.Deleted,
                    Prototype     = x.Prototype,
                    Semesters     = x.Semesters.Select(y => new SemesterVM
                    {
                        Subjects = y.SemesterSubjects.Select(z => new SubjectVM
                        {
                            Id            = z.Subject.Id,
                            Name          = z.Subject.Name,
                            Shifr         = z.Subject.Shifr,
                            Credits       = z.Subject.Credits,
                            Lec           = z.Subject.Lec,
                            Lab           = z.Subject.Lab,
                            Pr            = z.Subject.Pr,
                            UserId        = z.Subject.UserId,
                            Date          = z.Subject.Date,
                            UpdateDate    = z.Subject.UpdateDate,
                            Type          = z.Subject.Type,
                            Prerequisites = z.Subject.RelatedItems.Select(a => new SubjectVM
                            {
                                Id         = a.Related.Id,
                                Name       = a.Related.Name,
                                Shifr      = a.Related.Shifr,
                                Credits    = a.Related.Credits,
                                Lec        = a.Related.Lec,
                                Lab        = a.Related.Lab,
                                Pr         = a.Related.Pr,
                                UserId     = a.Related.UserId,
                                Date       = a.Related.Date,
                                UpdateDate = a.Related.UpdateDate,
                                Type       = a.Related.Type
                            }).ToList()
                        }).ToList(),
                        Electives = y.SemesterElectiveGroups.Select(z => new ElectiveGroupVM
                        {
                            Id         = z.ElectiveGroup.Id,
                            Name       = z.ElectiveGroup.Name,
                            Shifr      = z.ElectiveGroup.Shifr,
                            Credits    = z.ElectiveGroup.Credits,
                            Pr         = z.ElectiveGroup.Pr,
                            UserId     = z.ElectiveGroup.UserId,
                            Date       = z.ElectiveGroup.Date,
                            UpdateDate = z.ElectiveGroup.UpdateDate,
                            Type       = z.ElectiveGroup.Type,
                            Subjects   = z.ElectiveGroup.SubjectElectiveGroups.Select(a => new SubjectVM
                            {
                                Id            = a.Subject.Id,
                                Name          = a.Subject.Name,
                                Shifr         = a.Subject.Shifr,
                                Credits       = a.Subject.Credits,
                                Lec           = a.Subject.Lec,
                                Lab           = a.Subject.Lab,
                                Pr            = a.Subject.Pr,
                                UserId        = a.Subject.UserId,
                                Date          = a.Subject.Date,
                                UpdateDate    = a.Subject.UpdateDate,
                                Type          = a.Subject.Type,
                                Prerequisites = a.Subject.RelatedItems.Select(b => new SubjectVM
                                {
                                    Id         = b.RelatedId,
                                    Name       = b.Related.Name,
                                    Shifr      = b.Related.Shifr,
                                    Credits    = b.Related.Credits,
                                    Lec        = b.Related.Lec,
                                    Lab        = b.Related.Lab,
                                    Pr         = b.Related.Pr,
                                    UserId     = b.Related.UserId,
                                    Date       = b.Related.Date,
                                    UpdateDate = b.Related.UpdateDate,
                                    Type       = b.Related.Type
                                }).ToList()
                            }).ToList()
                        }).ToList()
                    }).ToList()
                }).Where(x => x.Deleted == 0).ToListAsync();
            }
            return(Ok(result));
        }