public ActionResult DeletePlaylist(AddPlaylistModel model) { // Get logged in user and if not logged in, redirect to login page var user = (UserDto)Session["user"]; _playlistsDao.DeletePlaylist(user, model.Playlist); return(RedirectToAction("Index", "Playlists")); }
public ActionResult AddPlaylist(AddPlaylistModel model) { // Get logged in user and if not logged in, redirect to login page var user = (UserDto)Session["user"]; _playlistsDao.CreatePlaylist(user, model.Playlist); _statsDao.IncrementCounter("playlists"); return(RedirectToAction("Index", "Playlists")); }
public async Task <IActionResult> AddPlaylist(AddPlaylistModel model, int userId) { var dateTimeNow = DateTime.Now; var createDate = $"{dateTimeNow.Day}.{dateTimeNow.Month}.{dateTimeNow.Year} {dateTimeNow.Hour}:{dateTimeNow.Minute}:{dateTimeNow.Second}"; var sharingLinkImage = ""; try { var user = await db.Users.FindAsync(userId); if (user == null) { return(new NotFoundObjectResult(new { msg = "Пользователь не найден" })); } if (model.PlaylistImage != null) { if (await cloudService.IfFileExists("", $"{user.Login}_playlist_{createDate}_" + model.PlaylistImage.FileName)) { return(new OkObjectResult(new { msg = $"В вашем хранилище уже есть файл {model.PlaylistImage.FileName}" })); } sharingLinkImage = await cloudService.AddFile("", $"{user.Login}_playlist_{createDate}_" + model.PlaylistImage.FileName, model.PlaylistImage.OpenReadStream()); } var playlist = new Playlist { PlaylistName = model.PlaylistName, PlaylistDescription = model.PlaylistDescription, PlaylistImageFile = model.PlaylistImage == null ? $"{options.Value.DefaultPlaylistImageFile}" : $"{user.Login}_playlist_{createDate}_" + model.PlaylistImage.FileName, PlaylistImageUrl = model.PlaylistImage == null ? $"{options.Value.DefaultPlaylistImageLink}" : sharingLinkImage, UserId = user.UserId, CreateDate = dateTimeNow }; db.Playlists.Add(playlist); await db.SaveChangesAsync(); var notificationResult = notificationManager.AddNotification(new AddNotification { UserId = userId, SourceId = playlist.PlaylistId, NotificationType = NotificationType.AddedPlaylist, Message = $"Пользователь {user.Login} добавил новый плейлист под названием {playlist.PlaylistName}" }).Result; if (!notificationResult.OperationCompleted) { throw new Exception(notificationResult.ErrorMessage); } return(new OkObjectResult(new { id = playlist.PlaylistId })); } catch { return(new StatusCodeResult(500)); } }
public IActionResult AddPlaylist([FromForm] AddPlaylistModel model) { return(playlistManager.AddPlaylist(model, UserId).Result); }