Exemplo n.º 1
0
        public async Task <IActionResult> LikeUser(int userId, int recipientId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var like = await _usersService.GetLike(userId, recipientId);

            if (like != null)
            {
                _genericsRepo.Delete(like);
            }

            if (await _genericsRepo.SaveAll())
            {
                return(BadRequest("Ai șters utilizatorul din lista de prieteni!"));
            }

            if (await _usersService.GetUser(recipientId) == null)
            {
                return(NotFound());
            }

            _usersService.AddLike(userId, recipientId, like);

            if (await _genericsRepo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to like user!"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddPost(Post post)
        {
            _postsService.AddPost(post);

            if (await _genericsRepo.SaveAll())
            {
                return(NoContent());
            }

            return(BadRequest("Something went wrong!"));
        }
        public async Task <IActionResult> AddPresentation(CompanyPresentation presentation)
        {
            if (await _companyPresentationsService.CompanyPresentationExists(presentation))
            {
                return(BadRequest("There is a presentation already at this hour or in this class!"));
            }

            _companyPresentationsService.AddCompanyPresentation(presentation);

            if (await _genericsRepo.SaveAll())
            {
                return(NoContent());
            }

            return(BadRequest("Something went wrong!"));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> AddComment(Comment comment)
        {
            if (comment.Content != "")
            {
                _commentsService.AddComment(comment);
            }
            else
            {
                return(BadRequest("Nu poți posta comentarii goale!"));
            }

            if (await _genericsRepo.SaveAll())
            {
                return(NoContent());
            }

            return(BadRequest("Something went wrong!"));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> AddSeminar(Seminar seminary)
        {
            int adminId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (await _seminarsService.SeminarExists(seminary, adminId))
            {
                return(BadRequest("The seminary you entered already exists!"));
            }

            _seminarsService.AddSeminar(seminary);

            if (await _genericsRepo.SaveAll())
            {
                return(NoContent());
            }

            return(BadRequest("Something went wrong!"));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> AddCourse(Course course)
        {
            int adminId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (await _coursesService.CourseExists(course, adminId))
            {
                return(BadRequest("The course you entered already exists!"));
            }

            _coursesService.AddCourse(course);

            if (await _genericsRepo.SaveAll())
            {
                return(NoContent());
            }

            return(BadRequest("Something went wrong!"));
        }
        public async Task <IActionResult> DeleteSpecialization(Specialization specialization)
        {
            _genericsRepo.Delete(specialization);

            if (await _genericsRepo.SaveAll())
            {
                return(NoContent());
            }
            return(BadRequest("Delete Failed!"));
        }
        public async Task <IActionResult> DeleteSubGroup(SubGroup subGroup)
        {
            _genericsRepo.Delete(subGroup);

            if (await _genericsRepo.SaveAll())
            {
                return(NoContent());
            }
            return(BadRequest("Delete Failed!"));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> DeleteClass(int id)
        {
            _adminService.DeleteClass(id);

            if (await _genericsRepo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception("Error deleting the class!");
        }
Exemplo n.º 10
0
        public void AddUserToDivisions(UserForRegisterDto userForRegister, User user, UserForDetailedDto userForDetailed)
        {
            if (userForRegister.Year != 0)
            {
                var specialization = _specializationsRepo.GetSpecializationByName(userForRegister.Specialization);

                var group = _groupsRepo.GetGroupByName(userForRegister.Group);

                var subGroup = _subGroupsRepo.GetSubGroupByName(userForRegister.SubGroup);

                UserSpecialization userSpecialization = new UserSpecialization
                {
                    UserId           = user.Id,
                    SpecializationId = specialization.Id
                };

                _genericsRepo.Add(userSpecialization);

                UserGroup userGroup = new UserGroup
                {
                    UserId  = user.Id,
                    GroupId = group.Id
                };

                _genericsRepo.Add(userGroup);

                UserSubGroup userSubGroup = new UserSubGroup
                {
                    UserId     = user.Id,
                    SubGroupId = subGroup.Id
                };

                _genericsRepo.Add(userSubGroup);

                userForDetailed.Specialization = specialization.Name;
                userForDetailed.Group          = group.Name;
                userForDetailed.SubGroup       = subGroup.Name;

                _genericsRepo.SaveAll();
            }
        }
Exemplo n.º 11
0
 public async Task <bool> SaveChangesInContext()
 {
     return(await _genericsRepo.SaveAll());
 }