public JsonResult SendMessage(Guid?serverId, string message) { if (string.IsNullOrWhiteSpace(message)) { return(Json(false)); } else { Chat msg = new Chat { ChatId = Guid.NewGuid(), Message = message, TimeSent = DateTime.Now, ServerId = serverId, UserId = User.Identity.GetUserId(), }; try { db.Chats.Add(msg); db.SaveChanges(); return(Json(true)); } catch (Exception) { return(Json(false)); } } }
public JsonResult FriendRequest(string sentToId) { // sent from is = userId // sent to is = user being sent request var sentFromId = User.Identity.GetUserId(); Friend friend = new Friend { SentFromId = sentFromId, SentToId = sentToId, IsAccepted = false, }; try { db.Friends.Add(friend); db.SaveChanges(); return(Json(true)); } catch (Exception) { return(Json(false)); } }
public ActionResult Create([Bind(Include = "ServerId,ServerName,ServerImage")] Server server, HttpPostedFileBase imageUpload) { if (imageUpload != null && ValidateFile(imageUpload)) { SaveServerImage(server, imageUpload); } if (ModelState.IsValid) { server.ServerId = Guid.NewGuid(); db.Servers.Add(server); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(server)); }