예제 #1
0
        public async Task <IActionResult> PutComment(int id, Comment comment)
        {
            if (id != comment.Id)
            {
                return(BadRequest());
            }

            _context.Entry(comment).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutTeammatePreference(int id, TeammatePreference teammatePreference)
        {
            if (id != teammatePreference.Id)
            {
                return(BadRequest());
            }

            _context.Entry(teammatePreference).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TeammatePreferenceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #3
0
        public async Task <ActionResult <DataBase.Models.Task> > ChangeRole([FromBody] JsonPatchDocument <DataBase.Models.Task> patchDoc, int Id)
        {
            if (patchDoc != null)
            {
                var task = _context
                           .Tasks
                           .FirstOrDefault(st => st.Id == Id);

                patchDoc.ApplyTo(task, ModelState);

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }


                _context.Entry(task).State = EntityState.Modified;

                await _context.SaveChangesAsync();

                return(new ObjectResult(task));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public async Task <ActionResult <ClassSubject> > PostClassSubject(ClassSubject classSubject)
        {
            _context.ClassSubjects.Add(classSubject);
            await _context.SaveChangesAsync();

            return(Created("", classSubject));
        }
        public async Task <ActionResult <ClassTech> > PostClassTeches(ClassTech classTech)
        {
            _context.ClassTeches.Add(classTech);
            await _context.SaveChangesAsync();

            return(Created("", classTech));
        }
        public async Task <ActionResult <object> > RunAlgo(Class @class)
        {
            var ques = await _context
                       .Questionnaires
                       .Where(que => que.ClassId == @class.Id)
                       .Include(que => que.TeammateAntipreferences)
                       .Include(que => que.TeammatePreferences)
                       .Include(que => que.Student)
                       .Include(que => que.TechPreferences)
                       .ThenInclude(que => que.Tech)
                       .ToListAsync();


            foreach (var que in ques)
            {
                Console.WriteLine(que.Student.Name);
            }
            Algorithm    algo   = new Algorithm(ques, 2, 4);
            List <Group> groups = algo.Run(@class);

            int i = 1;

            foreach (var group in groups)
            {
                Console.WriteLine("___________________-");


                Console.WriteLine("Group name:");
                Console.WriteLine(group.Name);
                _context
                .Groups
                .Add(group);
                await _context.SaveChangesAsync();

                Console.WriteLine(group.Id);
            }

            return(Created("", new { x = "d" }));
        }
예제 #7
0
        public async Task <ActionResult <UserDTO> > Register(User user)
        {
            var regex = new Regex("^[^\n\r\\s]+@knu\\.ua$");

            if (!regex.IsMatch(user.Email))
            {
                ModelState.AddModelError("Email", "Not a valid email");
                return(BadRequest(ModelState));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // try to find already exisiting user in DB
            var userByEmail = _context
                              .Users
                              .FirstOrDefault(entry => (entry.Email == user.Email));

            if (userByEmail != null)
            {
                ModelState.AddModelError("Email", "Duplicate email");
                return(BadRequest(ModelState));
            }

            PasswordHasher <User> pwh = new PasswordHasher <User>();

            user.Password = pwh.HashPassword(user, user.Password);

            if (User.Identity.IsAuthenticated)
            {
                Console.WriteLine("Xd already in");
            }

            _context.Users.Add(user);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetUser), new { id = user.Id }, ItemToDTO(user)));
        }