public async Task <IActionResult> AddDepartment(DepartmentForUpdateDto departmentForUpdateDto)
        {
            var depToCreate = _mapper.Map <Department>(departmentForUpdateDto);

            _repo.Add(depToCreate);

            if (await _repo.SaveAll())
            {
                return(Ok(depToCreate));
            }



            return(BadRequest());
            //return Ok();
        }
Example #2
0
        public async Task <IActionResult> LikeUser(int id, int recipientId)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var like = await _repo.GetLike(id, recipientId);

            if (like != null)
            {
                return(BadRequest("You already like this user"));
            }

            if (await _repo.GetUser(recipientId, false) == null)
            {
                return(NotFound());
            }

            like = new Like
            {
                LikerId = id,
                LikeeId = recipientId
            };

            _repo.Add <Like>(like);

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

            return(BadRequest("Failed to like user"));
        }
        public async Task <IActionResult> CreateMessage(int userId, MessageForCreationDto messageForCreationDto)
        {
            var sender = await _repo.GetUser(userId, false);

            if (sender.Id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            messageForCreationDto.SenderId = userId;

            var recipient = await _repo.GetUser(messageForCreationDto.RecipientId, false);

            if (recipient == null)
            {
                return(BadRequest("Could not find user"));
            }

            var message = _mapper.Map <Message>(messageForCreationDto);

            _repo.Add(message);

            if (await _repo.SaveAll())
            {
                var messageToReturn = _mapper.Map <MessageToReturnDto>(message);
                return(CreatedAtRoute("GetMessage", new { id = message.Id }, messageToReturn));
            }

            throw new Exception("Creating the message failed on save");
        }
Example #4
0
        public async Task <IActionResult> AddRegion(RegionForUpdateDto regionForUpdateDto)
        {
            var regionToCreate = _mapper.Map <Region>(regionForUpdateDto);

            _repo.Add(regionToCreate);

            if (await _repo.SaveAll())
            {
                return(Ok(regionToCreate));
            }



            return(BadRequest());
            //return Ok();
        }
Example #5
0
        public async Task <IActionResult> AddCourse(int id, CourseDto courseDto)
        {
            // var course = await _context.Courses.FirstOrDefaultAsync(x => x.Id == id);
            var course = _mapper.Map <Course>(courseDto);

            _portalRepository.Add(course);

            if (await _portalRepository.SaveAll())
            {
                var courseToReturn = _mapper.Map <CourseDto>(course);
                // return CreatedAtRoute("GetCourse", new {id = course.Id}, courseToReturn);
                return(Ok(course));
            }

            // return Ok(course);
            throw new Exception("Creating the message failed on save");
        }