public IActionResult New([FromBody] Post Post) { Post.CreatedAt = DateTime.Now; Post.UpdatedAt = DateTime.Now; Post.UserId = (int)HttpContext.Session.GetInt32("UserId"); Context.Posts.Add(Post); Context.SaveChanges(); return(Ok(Post)); }
public IActionResult New([FromBody] Allegiance Model) { Clan RequestingClan = Context.Clans.Where(c => c.Id == Model.ClanId).Single(); Clan RequesteeClan = Context.Clans.Where(c => c.Id == Model.ClanId_2).Single(); if (RequesteeClan != null && RequestingClan != null) { Context.Allegiances.Add(Model); Context.SaveChanges(); Notification NewNotification = new Notification() { CreatedAt = DateTime.Now, Text = $"{RequestingClan.Name} has requested and Alliance with you!", Type = NotificationType.CLAN, UserId = (int)HttpContext.Session.GetInt32("UserId"), Unread = true, }; Context.Notifications.Add(NewNotification); Context.SaveChanges(); return(Ok(Model)); } else { return(BadRequest("Missing or Invalid ClanId(s)")); } }
public IActionResult Update([FromBody] UserForm UpdateUser) { User User = Context.Users.Where(u => u.Id == (int)HttpContext.Session.GetInt32("UserId")).Single(); User.FirstName = UpdateUser.FirstName; User.LastName = UpdateUser.LastName; User.Email = UpdateUser.Email; Context.Users.Update(User); Context.SaveChanges(); User.Password = null; return(Ok(User)); }
public IActionResult New([FromRoute] int UserId, [FromBody] string message) { Notification notification = new Notification() { Text = message, Type = NotificationType.GENERAL, UserId = UserId }; Context.Notifications.Add(notification); Context.SaveChanges(); return(Ok(new { message = "Successfully added notification" })); }
public IActionResult Register([FromBody] User User) { _logger.LogInformation("Registering."); if (ModelState.IsValid) { PasswordHasher <User> Hasher = new PasswordHasher <User>(); string HashedPw = Hasher.HashPassword(User, User.Password); User.Password = HashedPw; Context.Users.Add(User); Context.SaveChanges(); HttpContext.Session.SetInt32("UserId", User.Id); User.Token = UserService.GenerateToken(User.Id); User.Password = null; return(Ok(new { user = User })); } else { return(Ok(new Exception("You f****d something up"))); } }
public IActionResult New([FromBody] Clan NewClan) { int?UserId = HttpContext.Session.GetInt32("UserId"); if (UserId != null) { User User = Context.Users.Where(u => u.Id == UserId).Single(); Context.Clans.Add(NewClan); Context.SaveChanges(); User.ClanId = NewClan.Id; User.Role = Clan.Roles.Founder; Context.Users.Update(User); Context.SaveChanges(); return(Ok(NewClan)); } else { return(Ok(new Exception("You are not logged in"))); } }