コード例 #1
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());
        }
コード例 #2
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());
        }
コード例 #3
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());
        }
コード例 #4
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());
        }
コード例 #5
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());
        }
コード例 #6
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());
        }
コード例 #7
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());
        }
コード例 #8
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());
        }
コード例 #9
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());
        }