public void Delete_WhenMessageIsValid_ReturnsSuccess() { var success = 1; var pokemon = GetFakeMessages()[0]; dataBaseMock.Setup(x => x.Delete(pokemon)).Returns(success); var result = messageRepository.Delete(pokemon); Assert.AreEqual(success, result); dataBaseMock.Verify(x => x.Delete(pokemon), Times.Once); }
public async Task <IActionResult> DeleteMessage(int id, int userId) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var messageFromRepo = await _repo.Get(id); if (messageFromRepo.SenderId == userId) { messageFromRepo.SenderDeleted = true; } if (messageFromRepo.ReceiverId == userId) { messageFromRepo.ReceiverDeleted = true; } if (messageFromRepo.SenderDeleted && messageFromRepo.ReceiverDeleted) { _repo.Delete(messageFromRepo); } if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception("Error deleting message"); }
private void removeRecursive(Section section) { if (section.ChildSections != null) { while (section.ChildSections.Any()) { removeRecursive(section.ChildSections.First()); } } if (section.Topics != null) { while (section.Topics.Any()) { var topic = section.Topics.First(); if (topic.Messages != null) { while (topic.Messages.Any()) { _messageRepository.Delete(topic.Messages.First().Id); } } _topicRepository.Delete(topic.Id); } } _sectionRepository.Delete(section.Id); }
public IActionResult Delete(MessageDto message) { var model = _mapper.Map <MessageDto, Message>(message); _repository.Delete(model); return(new NoContentResult()); }
public async Task <IActionResult> DeleteMessage(long id, long userId) { if (!CheckUserId(userId)) { return(Unauthorized()); } var messageFromRepo = await _messageRepo.GetMessage(id); if (messageFromRepo.SenderId == userId) { messageFromRepo.SenderDeleted = true; } if (messageFromRepo.RecipientId == userId) { messageFromRepo.RecipientDeleted = true; } if (messageFromRepo.SenderDeleted && messageFromRepo.RecipientDeleted) { _messageRepo.Delete(messageFromRepo); } if (await _messageRepo.SaveAll()) { return(NoContent()); } throw new Exception("Remove the message failed on save"); }
public void DeleteUser(User user) { if (user == null) { throw new ArgumentNullException(); } var userToDelete = GetUserById(user.UserId); if (userToDelete == null) { throw new ArgumentException ($"User with Id = {user.UserId} does not exists"); } profileRepository.Delete(userToDelete.User_additional_info); foreach (var message in userToDelete.Messages.ToList()) { messageRepository.Delete(message); } foreach (var topic in userToDelete.Topics.ToList()) { topicRepository.Delete(topic); } foreach (var moderatingQuery in userToDelete.SectionModerators.ToList()) { sectionModeratorsRepository.Delete(moderatingQuery); } ctx.Set <User>().Remove(userToDelete); ctx.SaveChanges(); }
public async Task <IActionResult> DeleteMessage(int messageId, int userId) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var message = await _messageRepo.GetMessage(messageId); // Only delete if both parties delete the message if (message.SenderId == userId) { message.SenderDeleted = true; } if (message.RecipientId == userId) { message.RecipientDeleted = true; } if (message.SenderDeleted && message.RecipientDeleted) { _messageRepo.Delete(message); } if (await _messageRepo.SaveAll()) { return(NoContent()); } throw new Exception("Error deleting message"); }
public MessageDTO Delete(int id) { MessageDAO resultMessageDAO = MessageRepository.Delete(id).Result; MessageDTO resultMessageDTO = converter.fromDAOTodTO(resultMessageDAO); return(resultMessageDTO); }
public void DeleteMessage(MessageEntity message) { NullRefCheck(); ArgumentNullCheck(message); messageRepository.Delete(message.ToDalMessage()); uow.Commit(); }
public async Task Delete(Guid[] messages, bool forOwner, CancellationToken cancel) { var deletedMessages = await _repository.Delete(messages, forOwner, cancel); await _hubContext.Clients .Group(deletedMessages[0].RoomId.ToString()) .SendAsync("MessagesDeleted", deletedMessages); }
public async Task <IActionResult> DeleteMessage(int id) { string userId = _messageRepository.GetMessageById(id).ApplicationUserId; string userEmail = (await _userManager.FindByIdAsync(userId)).Email; _messageRepository.Delete(id); return(RedirectToAction("UserDetails", "User", new { email = userEmail })); }
public IActionResult Delete(int id) { if (id > 0) { Message newAttraction = _messageRepository.Delete(id); } return(RedirectToAction("index")); }
public async Task <IActionResult> DeleteConfirmed(Guid?id) { var item = await _messageRepository.Get(id); await _messageRepository.Delete(item); return(RedirectToAction("Index")); }
public async Task <bool> RemoveEntityAsync(int tId) { return(await Task.Run(() => { Message message = _repository.GetSingleModel(a => a.MessageId == tId); return _repository.Delete(message); })); }
public void DeleteMessage(int id) { var message = messagesRepository.GetById(id); if (message != null) { messagesRepository.Delete(message); } }
public async Task <ActionResult <bool> > Delete(Guid id) { try { return(await _repo.Delete(id)); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public async Task <Result <object> > Handle(DeleteMessageCommand request, CancellationToken cancellationToken) { if ((await _messageRepository.Get(request.Id)) == null) { return(Result.NotFound <object>(null)); } await _messageRepository.Delete(request.Id); return(Result.NoContent <object>(null)); }
public void CleanInbox() { IEnumerable <Email> spam = _messageRepository.List() .Where(e => e.IsSpam()); foreach (int id in spam.Select(e => e.Id)) { _messageRepository.Delete(id); } _messageRepository.Save(); }
public ActionResult ConfirmDelete(Guid id) { try { _messageRepo.Delete(id); return(RedirectToAction(nameof(Index))); } catch { return(View("Index", "Home")); } }
public void Remove(int id) { var message = _messageRepository.FindById(id); if (message == null) { throw new NullReferenceException(); } _messageRepository.Delete(message.Id); _provider.SaveChanges(); }
public void TestDelete() { var entity = new Message(); entity.Id = "testId"; _repository.Create(entity); _repository.Delete(entity.Id); Assert.Null(_repository.GetById(entity.Id)); }
public async Task <IActionResult> Delete(long id) { var post = await _repo.GetMessage(id); if (post == null) { return(new NotFoundResult()); } await _repo.Delete(id); return(new OkResult()); }
public async Task <IActionResult> DeleteMessage(Guid id) { if (!await MessageExists(id)) { return(NotFound(id)); } await _messageRepository.Delete(id); await _context.SaveChangesAsync(); return(NoContent()); }
public async Task Delete_ExistingMessage_Ok() { var appId = Guid.NewGuid(); var channelId = Guid.NewGuid(); var messageId = Guid.NewGuid(); var client = await _factory.CreateAuthenticatedClient(); _messageRepository.Delete(appId, channelId, messageId) .Returns(true); var response = await client.DeleteAsync($"/api/v2/app/{appId}/channel/{channelId}/message/{messageId}"); response.EnsureSuccessStatusCode(); }
//Verwijdert een verlofverzoek bij id. public void Delete(long vacationid) { //Eerst worden berichten waarin het verlofverzoekid voorkomt, verwijdert. Dit zodat de applicatie niet vastloopt. var query = _messrepository.Get(filter => filter.VacationRequestID == vacationid); foreach (var item in query) { _messrepository.Delete(item.MessageID); } _repository.Delete(vacationid); _uow.Commit(); }
public String DeleteMessage(Message message) { if (_messageRepository.Records.Any(m => m.LecturerId == message.LecturerId && m.StudentId == message.StudentId && m.Details == message.Details)) { _messageRepository.Delete(message); return("successfully Deleted"); } else { return("No such message"); } }
public ActionResult DeleteConfirmed(MessageEditModel messageEM) { Message m = new Message { MessageId = messageEM.Id }; messageRepository.Delete(m); if (messageEM.ToPage != 1 && topicRepository.GetMessagesForTopicOnPage( new Topic { TopicId = messageEM.ToTopic }, messageEM.ToPage, PagingConfig.Messages_per_page).Count() == 0) { messageEM.ToPage--; } return(RedirectToRoute("Topic", new { Action = "Topic", id = messageEM.ToTopic, page = messageEM.ToPage })); }
/// <summary> /// 删除私信 /// </summary> /// <param name="messageId">私信Id</param> /// <param name="sessionId">私信会话Id</param> /// <returns>是否删除成功:true-成功,false-不成功</returns> public bool Delete(long messageId, long sessionId) { Message message = messageRepository.Get(messageId); if (message == null) { return(false); } EventBus <Message> .Instance().OnBefore(message, new CommonEventArgs(EventOperationType.Instance().Delete())); int affectCount = messageRepository.Delete(message, sessionId); EventBus <Message> .Instance().OnAfter(message, new CommonEventArgs(EventOperationType.Instance().Delete())); return(affectCount > 0); }
public void DeleteAllByUserId(long userId) { var flag = true; while (flag) { var mess = _messageRepository.Get(x => x.AspNetUser.Id == userId); if (mess == null) { flag = false; } else { _messageRepository.Delete(mess.Id); } } }
public async Task <ServiceResult <Message> > Delete(string messageId, string userId) { var messageEntity = await messageRepository.Get(messageId); if (messageEntity == null) { return(new ServiceResult <Message>($"No message with id {messageId}")); } if (messageEntity.SenderId != userId) { return(new ServiceResult <Message>("You can't delete this message")); } messageRepository.Delete(messageEntity); return(new ServiceResult <Message>(messageEntity)); }