public IHttpActionResult PostMessage(int toUserId, string deviceId, string encryptedMessage) { var user = UserManager.FindByName(User.Identity.Name); var message = new Message() { DeviceId = deviceId, EncryptedMessage = encryptedMessage, ToUserId = toUserId, FromUserId = user.UserId }; if (user.UserId == message.ToUserId) { return BadRequest("Can't send message to self."); } user.KinderPoints++; _db.UserDevices.AddOrUpdate(user); _db.Messages.Add(message); _db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = message.Id }, message); }
public IHttpActionResult PostMessages(int toUserId, List<string> deviceIds, List<string> encryptedMessages) { // This would be better as a binded model... but whatever. This is easier for now :\ var user = UserManager.FindByName(User.Identity.Name); for (var i = 0; i < deviceIds.Count; i++) { var message = new Message() { DeviceId = deviceIds[i], EncryptedMessage = encryptedMessages[i], ToUserId = toUserId, FromUserId = user.UserId }; if (user.UserId == message.ToUserId) { return BadRequest("Can't send message to self."); } user.KinderPoints++; _db.Messages.Add(message); } _db.UserDevices.AddOrUpdate(user); _db.SaveChanges(); return Ok(); }