Beispiel #1
0
        public JsonResult AddRoomContacts(int roomId, string[] UIDs)
        {
            GenericResponse result = new GenericResponse()
            {
                IsSuccessful = false
            };

            try
            {
                if (roomId < 1 || UIDs.IsNullOrEmpty())
                {
                    result.ErrorMessage = "Bad request.";
                    return(new JsonResult(result));
                }

                Room room = _roomService.GetRoom(roomId);

                if (room == null || !RoomPermissionHelper.CanAddRoomContact(_context.CurrentUser, room))
                {
                    result.ErrorMessage = "You do not have permission to add a contact to this room.";
                    return(new JsonResult(result));
                }

                // Now add the contacts to the room (UIDs not found in the actionUser's contacts will be filtered out)
                _roomService.AddRoomContacts(_context.CurrentUser, room, UIDs);

                // If we got this far we are successful
                result.IsSuccessful = true;
            }
            catch (Exception e)
            {
                result.ErrorMessage = "An exception occurred.";
                _exceptionService.ReportException(e);
            }

            return(new JsonResult(result));
        }