Пример #1
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());
        }
        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());
        }
Пример #3
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());
        }
Пример #4
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());
        }