public void AddMessage(Messages entityToAdd) { IMessagesRepository repo = new MessagesRepository(getEntities()); Entities.Messages entityToAdd2 = Mapper.Map <Messages, Entities.Messages>(entityToAdd); repo.Add(entityToAdd2); }
public ActionResult Add(int containerId, string text) { if (!IsAuthenticated || AuthenticationService.CurrentUser.Role < UserRoles.User) { var error = new { Error = "У вас прав нет." }; return(Json(error, JsonRequestBehavior.AllowGet)); } try { ValidateAndGetContainer(containerId); } catch (Exception e) { var error = new { Error = e.Message }; return(Json(error, JsonRequestBehavior.AllowGet)); } Message message = new Message { UserId = CurrentUser.Id, ContainerId = containerId, Date = DateTime.Now, Text = text }; message = MessagesRepository.Add(message); MessagesRepository.SaveChanges(); var response = new { Html = ConvertViewToString("Content/_Message", message) }; return(Json(response, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> Create(int dialogId, string message) { message = message?.Trim(); if (string.IsNullOrEmpty(message)) { return(StatusCode(400, "Сообщение не должно быть пустым")); } if (!await _dialogsRepository.Any(p => p.Id == dialogId)) { return(StatusCode(404, "Диалог с данным идентификатором не найден")); } var userId = CurrentUserId(); var messageDb = new Message() { Text = message, UserId = userId, DialogId = dialogId, }; if (!await _messagesRepository.Add(messageDb)) { return(StatusCode(500, "Не удалось добавить сообщение. Сообщите нам об этой ошибке")); } return(Ok(messageDb.Id)); }
public Message AddMessage(Message message) { message.MessageSentOn = DateTime.Now; if (message.From == default(ObjectId) || message.To == default(ObjectId)) { return(null); } return(MessagesRepository.Add(message)); }
public IActionResult Create([FromBody] Message msg) { if (msg == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } _msgRepo.Add(msg); return(CreatedAtAction(nameof(GetById), new { id = msg.Id }, msg)); }
public void Add() { var repo = new MessagesRepository(fixture.Db); var msg = new Message { Title = "New message", Body = "My body" }; var m = repo.Add(msg); Assert.Equal(4, m.Id); }
public OperationResult SendMessage(string text) { var settings = _appConnectionSettings.Get(); var messagesRepository = new MessagesRepository(); try { var ipPoint = new IPEndPoint(IPAddress.Parse(settings.Host), settings.Port); var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(ipPoint); byte[] data = Encoding.Unicode.GetBytes(text); socket.Send(data); data = new byte[256]; var builder = new StringBuilder(); do { var bytes = socket.Receive(data, data.Length, 0); builder.Append(Encoding.Unicode.GetString(data, 0, bytes)); } while (socket.Available > 0); Console.WriteLine("Application B answered: " + builder); messagesRepository.Add(new Message(text, DateTime.Now, true)); messagesRepository.Save(); socket.Shutdown(SocketShutdown.Both); socket.Close(); return(OperationResult.Success()); } catch (Exception ex) { messagesRepository.Add(new Message(text, DateTime.Now, false)); messagesRepository.Save(); return(OperationResult.Failed(ex.Message)); } }
public ActionResult CreateMessage(Message message) { message.DatePosted = DateTime.Now; message.Author = User.Identity.Name; using (var repo = new MessagesRepository()) { repo.Add(message); } return RedirectToAction("ThreadMessages", new { id = message.ThreadId }); }
public ActionResult Create(Messages message) { try { messagesRepository.Add(message); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public void Add_Test() { var repository = new MessagesRepository(); var message = new Message { Title = "Unit test message", Text = "Unit test text message" }; var actual_id = repository.Add(message); var all = repository.GetAll().ToArray(); Assert.AreEqual(actual_id, message.Id); CollectionAssert.Contains(all, message); //StringAssert.Matches(); }
public HttpResponseMessage Post([FromBody] Message value, [ValueProvider(typeof(HeaderValueProviderFactory <String>))] String sessionKey) { var user = usersRepository.GetBySessionKey(sessionKey); if (user == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid session key")); } value.Conversation.Messages = new Collection <Message>(); messagesRepository.Add(value); var receiver = (value.Conversation.FirstUser.Username == user.Username) ? value.Conversation.SecondUser : value.Conversation.FirstUser; usersRepository.AddMissedConversation(receiver, value.Conversation); return(Request.CreateResponse(HttpStatusCode.OK)); }
public IDtoOutObjects Send(DtoInMessage dtoInMessage) { DtoOutError error = new DtoOutError(); if (TokenTools.Authentication(dtoInMessage.Token, dtoInMessage.DeviceName)) { Message message = null; try { message = new Message(dtoInMessage); } catch (ObjectIsNotValidException ex) { error.Exception = ex; error.Message = "this chatroom does not exists"; return(error); } if (ChatRoomTools.getListIdChatRoomFromUser(TokenTools.getUserFromToken(dtoInMessage.Token).Id).Contains(message.IdChatRoom)) { error.Exception = new MessageIsNotInYourListOfChatRooms(); error.Message = "Message is not in your list of chatRooms"; return(error); } Message result = _messagesRepository.Add(message); _messagesRepository.Save(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <Message, DtoOutMessage>(); }); IMapper mapper = config.CreateMapper(); DtoOutMessage dtoOutMessage = new DtoOutMessage(); mapper.Map(result, dtoOutMessage); return(dtoOutMessage); } else { NotAuthenticatedException ex = new NotAuthenticatedException(); error.Exception = ex; return(error); } }
public IActionResult Post(Message mess) { _messageRepo.Add(mess); return(NoContent()); }
public Response Post([FromBody] Messages value) { return(repo.Add(value)); }