public FriendGroupDTO UpdateFriendGroup(FriendGroupDTO friendGroup)
        {
            FriendGroup friendG = _friendGroupRepository.Find(friendGroup.Id);

            if (friendG == null)
            {
                throw new APIException("The friend groups does not exist!", StatusCodes.Status404NotFound);
            }
            friendG = _mapper.Map <FriendGroup>(friendGroup);
            _friendGroupRepository.Update(friendG);
            return(_mapper.Map <FriendGroupDTO>(friendG));
        }
Ejemplo n.º 2
0
 public IActionResult FindFriendGroup(int groupId)
 {
     try
     {
         FriendGroupDTO friendGroup = _friendsGroupsService.FindGroup(groupId);
         return(Ok(friendGroup));
     }
     catch (APIException ex)
     {
         ErrorMessage err = new ErrorMessage {
             message = ex.Message
         };
         return(StatusCode(ex.StatusCode, err));
     }
 }
        public FriendGroupDTO CreateFriendGroup(FriendGroupDTO friendGroup)
        {
            User u = _userRepository.FindUser(friendGroup.AdminId);

            if (u == null)
            {
                throw new APIException("The user does not exist!", StatusCodes.Status404NotFound);
            }

            friendGroup.CreateDate = DateTime.Now;
            FriendGroup friendG = _mapper.Map <FriendGroup>(friendGroup);
            FriendGroup fg      = _friendGroupRepository.Add(friendG);

            CreateMember(fg.Id, fg.AdminId);
            return(friendGroup);
        }
Ejemplo n.º 4
0
 public IActionResult UpdateFriendGroup([FromBody] FriendGroupDTO friendGroup)
 {
     if (!ModelState.IsValid)
     {
         return(StatusCode(400, "bad data!"));
     }
     try
     {
         FriendGroupDTO friendG = _friendsGroupsService.UpdateFriendGroup(friendGroup);
         return(Ok(friendG));
     }
     catch (APIException ex)
     {
         ErrorMessage err = new ErrorMessage {
             message = ex.Message
         };
         return(StatusCode(ex.StatusCode, err));
     }
 }