public IActionResult Promote(int id) { var contentType = Request.ContentType; User user = _userData.GetById(id); if (user == null) { return(NotFound()); } if (user.Role == RoleType.Admin) { return(BadRequest()); } user.Role = RoleType.Admin; user = _userData.Update(user); if (contentType != null) { if (contentType.Equals("application/json")) { UserForVideoComment userDto = UserForVideoComment.ConvertUserForVideoComment(user); return(Json(userDto)); } else if (contentType.Equals("text/html")) { SingleUserDTO newDTO = SingleUserDTO.ConvertUserToDTO(user); return(View("SingleUserInfo", newDTO)); } else if (contentType.Equals("application/x-www-form-urlencoded")) { return(RedirectToAction(nameof(GetById), id)); } return(StatusCode(415)); } return(Json("Success")); }
public IActionResult EditUser(AddUserDTO user, IFormFile image) { if (ModelState.IsValid) { if (_userData.ExistUsername(user.Username, user.Id)) { ViewBag.Message = "Username already exist"; return(Json("Username aleady exist")); } var editUser = _userData.GetById(user.Id); if (editUser == null) { return(NotFound()); } editUser.FirstName = user.FirstName; editUser.LastName = user.LastName; if (user.Password != null) { editUser.Password = user.Password; } editUser.Email = user.Email; editUser.Description = user.Description; if (user.Image != null) { editUser.ProfilePictureUrl = AddImage(editUser.Username, user.Image); } editUser = _userData.Update(editUser); var contentType = Request.ContentType; if (contentType != null) { if (contentType.Equals("application/json")) { UserForVideoComment userDto = UserForVideoComment.ConvertUserForVideoComment(editUser); return(Json(userDto)); } else if (contentType.Equals("text/html")) { SingleUserDTO newDTO = SingleUserDTO.ConvertUserToDTO(editUser); return(View("SingleUserInfo", newDTO)); } else if (contentType.Equals("application/x-www-form-urlencoded")) { return(RedirectToAction(nameof(GetById), user.Id)); } return(RedirectToAction(nameof(GetById), user.Id));; } return(Json("Success")); } else { return(BadRequest()); } }
public IActionResult GetLoggedInUser() { var loggedInUserId = HttpContext.Session.GetString("LoggedInUserId"); var contentType = Request.ContentType; if (loggedInUserId == null) { if (contentType != null) { if (contentType.Equals("application/json")) { return(NoContent()); } } return(Json(null)); } User user = _userData.GetById(long.Parse(loggedInUserId)); if (user == null) { if (contentType != null) { if (contentType.Equals("application/json")) { return(NoContent()); } } return(Json(null)); } if (contentType != null) { if (contentType.Equals("application/json")) { UserForVideoComment userDto = UserForVideoComment.ConvertUserForVideoComment(user); return(Json(userDto)); } else if (contentType.Equals("text/html")) { SingleUserDTO newDTO = SingleUserDTO.ConvertUserToDTO(user); return(View("SingleUserInfo", newDTO)); } return(StatusCode(415)); } return(Json(user)); }