public IHttpActionResult GetChatsOfUser(int id, int?page = null, int pageSize = 10) { Logger.log.Debug("at ChatController.GetChatsOfUser"); IQueryable <UserServiceReference.ChatDTO> chats = null; if (!this.CheckUserIdAcces(id)) { Logger.log.Error("at ChatController.GetChatsOfUser - User request denied"); return(new Forbidden("User cannot look at other chats!")); } using (var client = SoapProvider.GetUserServiceClient()) { chats = client.GetChatsOfUser(id).AsQueryable(); } if (chats == null) { Logger.log.Error("at ChatController.GetChatsOfUser - Error at database"); return(InternalServerError()); } var data = this.ApplyPaging(chats, page.Value, pageSize, "GetChatsOfUser"); return(Ok(chats)); }
public IHttpActionResult GetAllUsersFromChat(int userId, string chat, int?page = null, int pageSize = 10) { Logger.log.Debug("at ChatController.GetAllUsersFromChat"); IQueryable <UserInfoDTO> users = null; if (!this.CheckUserIdAcces(userId)) { Logger.log.Error("at ChatController.GetAllUsersFromChat - User request denied"); return(new Forbidden("User cannot have acces to other chats!")); } int chatId = this.CreateChatIdFromProxy(chat); using (var client = SoapProvider.GetChatServiceClient()) { if (!this.IfUserHasAccesToChat(client, chatId, userId)) { Logger.log.Error("at ChatController.GetChatById - User request denied"); return(new Forbidden("User cannot have acces to other chat!")); } users = client.GetAllUsersFromChat(chatId).AsQueryable(); } if (users == null) { Logger.log.Error("at ChatController.GetAllUsersFromChat - Error at database"); return(InternalServerError()); } var data = this.ApplyPaging(users, page.Value, pageSize, "GetAllUsersFromChat"); return(Ok(data)); }
public IHttpActionResult GetChatById(int userId, string chat) { Logger.log.Debug("at ChatController.GetChatById"); ChatDTO chatDTO = null; if (!this.CheckUserIdAcces(userId)) { Logger.log.Error("at ChatController.GetChatById - User request denied"); return(new Forbidden("User cannot have acces to other chat!")); } int chatId = this.CreateChatIdFromProxy(chat); using (var client = SoapProvider.GetChatServiceClient()) { if (!this.IfUserHasAccesToChat(client, chatId, userId)) { Logger.log.Error("at ChatController.GetChatById - User request denied"); return(new Forbidden("User cannot have acces to other chat!")); } chatDTO = client.GetChatById(chatId); } if (chatDTO == null) { Logger.log.Error("at ChatController.GetChatById - Error at database"); return(InternalServerError()); } return(Ok(chatDTO)); }
public IHttpActionResult AddChat(int userId, ChatDTO chat) { Logger.log.Debug("at ChatController.AddChat"); int createdChatId; if (!this.CheckUserIdAcces(userId)) { Logger.log.Error("at ChatController.AddChat - User request denied"); return(new Forbidden("User cannot add chat to other people!")); } using (var client = SoapProvider.GetChatServiceClient()) { createdChatId = client.AddChat(chat); if (createdChatId == -1) { Logger.log.Error("at ChatController.AddChat - Error at database"); return(InternalServerError()); } if (!client.AddUser(createdChatId, userId)) { Logger.log.Error("at ChatController.AddChat - Error at database"); return(InternalServerError()); } } return(Ok(createdChatId)); }
public IHttpActionResult UpdateProfile(int id, [FromBody] UserInfoDTO dto) { Logger.log.Debug("at UserController.UpdateProfile"); dto.Id = id; if (!this.CheckUserIdAcces(id)) { Logger.log.Error("at UserController.UpdateProfile - User request denied"); return(new Forbidden("User cannot modify other profile!")); } using (var client = SoapProvider.GetUserServiceClient()) { try { var result = client.UpdateUser(dto); if (!result.Result) { Logger.log.Error("at UserController.UpdateProfile - " + result.Info); return(BadRequest((string)result.Info)); } } catch (Exception ex) { return(BadRequest(ex.ToString())); } } return(Ok()); }
public IHttpActionResult GetWayBetweenUsers(int id1, int id2, int?page = null, int pageSize = 10) { Logger.log.Debug("at UserController.GetWayBetweenUsers"); IQueryable <UserInfoDTO> friends = null; if (!this.CheckUserIdAcces(id1)) { Logger.log.Error("at UserController.GetWayBetweenUsers - User request denied"); return(new Forbidden("User cannot look at other friens way!")); } using (var client = SoapProvider.GetUserServiceClient()) { friends = SoapProvider.GetUserServiceClient().GetWayBetweenUsers(id1, id2).AsQueryable(); } if (friends == null) { Logger.log.Error("at UserController.GetWayBetweenUsers - Error at database"); return(InternalServerError()); } var data = this.ApplyPaging(friends, page.Value, pageSize, "GetWayBetweenUsers"); return(Ok(data)); }
public IHttpActionResult DeleteAccount(int id) { Logger.log.Debug("at AccountController.DeleteAccount"); if (!this.CheckUserIdAcces(id)) { Logger.log.Error("at AccountController.DeleteAccount - User request denied"); return(new Forbidden("User cannot modify other profile!")); } using (var client = SoapProvider.GetUserServiceClient()) { try { var result = client.DeleteUser(id); if (!result.Result) { Logger.log.Error("at AccountController.DeleteAccount - " + result.Info); return(BadRequest((string)result.Info)); } } catch (Exception ex) { return(BadRequest(ex.ToString())); } } return(Ok()); }
public IHttpActionResult AddMessage(int userId, string chat, MessageDTO message) { Logger.log.Debug("at ChatController.AddMessage"); int createdMessageId; if (!this.CheckUserIdAcces(userId)) { Logger.log.Error("at ChatController.AddMessage - User request denied"); return(new Forbidden("User cannot send message from other accounts!")); } if (userId != message.UserId) { Logger.log.Error("at ChatController.AddMessage - User request denied"); return(new Forbidden("User cannot send message from other accounts!")); } int chatId = this.CreateChatIdFromProxy(chat); using (var client = SoapProvider.GetChatServiceClient()) { if (!this.IfUserHasAccesToChat(client, chatId, userId)) { Logger.log.Error("at ChatController.GetChatById - User request denied"); return(new Forbidden("User cannot have acces to other chat!")); } createdMessageId = client.AddMessage(chatId, message); if (createdMessageId == -1) { Logger.log.Error("at ChatController.AddMessage - Error at database"); return(InternalServerError()); } if (chat == "bot") { using (var botClient = SoapProvider.GetBotServiceClient()) { var messageToBot = new BotServiceReference.MessageDTO() { NewContent = message.NewContent, UserId = message.UserId }; botClient.SendMessageToBot(messageToBot, chatId); } } } return(Ok(createdMessageId)); }
public IHttpActionResult GetUserById(int id) { Logger.log.Debug("at UserController.GetUserById"); UserInfoDTO user = null; using (var client = SoapProvider.GetUserServiceClient()) { user = client.GetUserById(id); } if (user == null) { Logger.log.Error("at UserController.GetUserById - Error at database"); return(InternalServerError()); } return(Ok(user)); }
public IHttpActionResult GetUserFriends(int id, int?page = null, int pageSize = 10) { Logger.log.Debug("at UserController.GetUserFriends"); IQueryable <UserInfoDTO> friends = null; using (var client = SoapProvider.GetUserServiceClient()) { friends = SoapProvider.GetUserServiceClient().GetUserFriends(id).AsQueryable(); } if (friends == null) { Logger.log.Error("at UserController.GetUserFriends - Error at database"); return(InternalServerError()); } var data = this.ApplyPaging(friends, page.Value, pageSize, "GetUserFriends"); return(Ok(data)); }
public IHttpActionResult AddUserToChat(int userId, string chat, int newUserId) { Logger.log.Debug("at ChatController.AddUserToChat"); if (userId == newUserId) { Logger.log.Error("at ChatController.AddUserToChat - User cannot add himself to chat"); return(BadRequest("User cannot add himself to chat")); } if (!this.CheckUserIdAcces(userId)) { Logger.log.Error("at ChatController.AddUserToChat - User request denied"); return(new Forbidden("User has no acces!")); } //if (userdId == SoapProvider.GetBotServiceClient()) int chatId = 0; if (!int.TryParse(chat, out chatId)) { return(BadRequest("Bad chat id, or cannot add user to chat with a bot")); } using (var client = SoapProvider.GetChatServiceClient()) { if (!this.IfUserHasAccesToChat(client, chatId, userId)) { Logger.log.Error("at ChatController.GetChatById - User request denied"); return(new Forbidden("User cannot have acces to other chat!")); } if (!client.AddUser(chatId, newUserId)) { Logger.log.Error("at ChatController.AddUserToChat - Error at database"); return(InternalServerError()); } } return(Ok()); }
public IHttpActionResult GetUserByAccountName(string name) { Logger.log.Debug("at AccountController.GetUserByAccountName"); UserInfoDTO user = null; using (var client = SoapProvider.GetUserServiceClient()) { user = client.GetAllUsers() .AsQueryable() .Where(item => item.UserName == name) .ToList() .Single(); } if (user == null) { Logger.log.Error("at AccountController.GetUserByAccountName - Error at database"); return(BadRequest("User not found")); } return(Ok(user)); }
public IHttpActionResult Register(AccountDTO dto) { Logger.log.Debug("at AccountController.Register"); if (!ModelState.IsValid) { Logger.log.Error("at AccountController.Register - Bad model state"); return(BadRequest(ModelState)); } OperationResultDTO result = null; using (var client = SoapProvider.GetUserServiceClient()) { try { if (client.FindUserByUserName(dto.UserName) != null) { return(BadRequest("User with this name is loginned")); } result = client.AddAccount(dto); if (!result.Result) { Logger.log.Error("at AccountController.Register - " + result.Info); return(BadRequest((string)result.Info)); } } catch (Exception ex) { return(BadRequest(ex.ToString())); } } return(Ok((int)result.Info)); }