public void GetPartition_InsertEntitiesInTwoPartitions_CorrectPartitionAndCountReturned() { var userMediaList = new List <UserMedia>(); for (int i = 1; i <= 150; i++) { var entity = new UserMedia("test") { StorageFormat = "Test", Type = "Test" }; if (i > 75) { entity.PartitionKey = UserMedia.FormatPartitionKey("two"); entity.UserId = "two"; } userMediaList.Add(entity); } Task <IList <TableResult> > insertTask = _repo.InsertBatchAsync(userMediaList); insertTask.Wait(); IEnumerable <UserMedia> getResult = _repo.GetPartition(userMediaList[0].PartitionKey); Assert.AreEqual(getResult.Count(), 75, "Unexpected result count returned"); Assert.AreEqual(getResult.First().PartitionKey, userMediaList[0].PartitionKey, "Wrong partition key returned"); }
public async Task PostImage(int albumId, AddImageToAlbum createRequest) { MediaAlbum albumEntity = await DbContext.MediaAlbums .SingleOrDefaultAsync(a => a.MediaAlbumId == albumId); if (albumEntity == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } if (albumEntity.UserId != UserId) { throw new HttpResponseException(HttpStatusCode.Forbidden); } UserMedia mediaEntity = await DbContext.UserMedias .SingleOrDefaultAsync(um => um.UserMediaId == createRequest.MediaId); if (mediaEntity == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } if (mediaEntity.UserId != UserId) { throw new HttpResponseException(HttpStatusCode.Forbidden); } await AlbumOperations.AddMediaToAlbumAsync(DbContext, albumEntity, mediaEntity, createRequest); }
public void GetPartitionAsync_InsertEntitiesInTwoPartitions_CorrectPartitionAndCountReturned() { var userMediaList = new List <UserMedia>(); for (int i = 1; i <= 150; i++) { var entity = new UserMedia("one") { StorageFormat = "Test", Type = "Test" }; if (i > 75) { entity.PartitionKey = UserMedia.FormatPartitionKey("two"); entity.UserId = "two"; } userMediaList.Add(entity); } Task <IList <TableResult> > insertTask = _repo.InsertBatchAsync(userMediaList); insertTask.Wait(); Assert.AreEqual(insertTask.Result.Where(r => r.HttpStatusCode == 201 && ((UserMedia)r.Result).PartitionKey == userMediaList[0].PartitionKey).Select(r => r).Count(), 75, "Unexpected result count returned for first group"); Assert.AreEqual(insertTask.Result.Where(r => r.HttpStatusCode == 201 && ((UserMedia)r.Result).PartitionKey == userMediaList[149].PartitionKey).Select(r => r).Count(), 75, "Unexpected result count returned for second group"); }
public static async Task <AlbumItem> GetMediaAsync( ApplicationDbContext dbContext, int mediaId) { UserMedia entity = await dbContext.UserMedias .Include(a => a.Description) .Include(a => a.Likes.Select(like => like.User)) .Include(a => a.CommentThread.Comments.Select(c => c.Text)) .Include(a => a.CommentThread.Comments.Select(c => c.User.Avatar)) .SingleOrDefaultAsync(a => a.UserMediaId == mediaId); if (entity == null) { return(null); } return(new AlbumItem { Id = entity.UserMediaId, UserId = entity.UserId, Title = entity.Title, Description = entity.Description?.Content, CreatedTime = entity.CreatedUtc.ToString("s"), CreatedTimeAgo = TimeOperations.GetTimeAgo(entity.CreatedUtc), MediaUrl = UserMediaOperations.GetUrl(entity), LikeUrl = UserMediaOperations.GetLikeUrl(entity), LikeGroups = LikeOperations.MakeLikeGroups(entity.Likes), CommentUrl = UserMediaOperations.GetCommentUrl(entity), Comments = CommentOperations.GetComments(entity.CommentThread) }); }
protected void AddToUser_OnClick(object sender, EventArgs e) { var usersMediaDetails = new UserMedia(); usersMediaDetails.MediaID = MediaDetailToAdd.MediaID; usersMediaDetails.UserID = BasePage.CurrentUser.ID; usersMediaDetails.DateCreated = usersMediaDetails.DateLastModified = DateTime.Now; //usersMediaDetails.PermissionID = PermissionsMapper.GetPermissionsFromEnum(PermissionsEnum.AccessProtectedSections).ID; var currentMediaDetail = BaseMapper.GetObjectFromContext((MediaDetail)MediaDetailToAdd); currentMediaDetail.Media.UsersMedias.Add(usersMediaDetails); var returnObj = MediaDetailsMapper.Update(currentMediaDetail); if (!returnObj.IsError) { BasePage.DisplaySuccessMessage("Successfully added to My Plan"); UpdateVisibility(); } else { BasePage.DisplayErrorMessage("Error adding to My Plan", returnObj.Error); } }
public RedirectToRouteResult GiveBorrowedMediaBackRequest(int userMediaId, IPrincipal user) { UserMedia userMedia = UserMediaService.Instance.GetUserMediaById(userMediaId); IQueryable <BorrowedDetails> borrowed = UserMediaService.Instance.GetAllBorrowedFromMediaByUser(user.Identity.Name); var borrowedMedia = (from i in borrowed where i.UserMedia.Id == userMedia.Id && i.DateOfReturn > DateTime.Now select i).Single(); borrowedMedia.TakeBackRequest = true; UserMediaService.Instance.Save(); if (userMedia.GetType() == typeof(UserMovie)) { return(RedirectToAction("Movie", "Media", new { username = userMedia.User.Username, id = ((UserMovie)userMedia).MovieId })); } else if (userMedia.GetType() == typeof(UserBook)) { return(RedirectToAction("Book", "Media", new { username = userMedia.User.Username, id = ((UserBook)userMedia).BookId })); } else if (userMedia.GetType() == typeof(UserTV_Show)) { return(RedirectToAction("TVShow", "Media", new { username = userMedia.User.Username, id = ((UserTV_Show)userMedia).Season.TV_ShowId })); } else { return(null); } }
public RedirectToRouteResult TakeBorrowedMediaBack(int userMediaId, IPrincipal user) { UserMedia userMedia = UserMediaService.Instance.GetUserMediaById(userMediaId); userMedia.MediaStatus = Models.UserMediaStatusEnum.NichtVerborgt.ToString(); IQueryable <BorrowedDetails> borrowed = UserMediaService.Instance.GetAllBorrowedAwayMediaByUser(userMedia.User.Username); var details = (from i in borrowed where i.UserMedia.Id == userMediaId && i.DateOfReturn > DateTime.Now select i).Single(); details.DateOfReturn = DateTime.Now; details.TakeBackRequest = false; UserMediaService.Instance.Save(); if (userMedia.GetType() == typeof(UserMovie)) { return(RedirectToAction("Movie", "Media", new { username = userMedia.User.Username, id = ((UserMovie)userMedia).MovieId })); } else if (userMedia.GetType() == typeof(UserBook)) { return(RedirectToAction("Book", "Media", new { username = userMedia.User.Username, id = ((UserBook)userMedia).BookId })); } else if (userMedia.GetType() == typeof(UserTV_Show)) { return(RedirectToAction("TVShow", "Media", new { username = userMedia.User.Username, id = ((UserTV_Show)userMedia).Season.TV_ShowId })); } else { return(null); } }
private void HandleDelete(IEnumerable <UserMedia> selectedUserMediaDetails) { selectedItem = BaseMapper.GetObjectFromContext((MediaDetail)selectedItem); Return obj = BaseMapper.GenerateReturn(); foreach (UserMedia selectedUserMediaDetail in selectedUserMediaDetails) { UserMedia item = BaseMapper.GetObjectFromContext(selectedUserMediaDetail); selectedItem.Media.UsersMedias.Remove(selectedUserMediaDetail); obj = UsersMediasMapper.DeletePermanently(selectedUserMediaDetail); if (obj.IsError) { break; } } if (obj.IsError) { BasePage.DisplayErrorMessage("Error deleting association", obj.Error); } else { BasePage.DisplaySuccessMessage("Successfully deleted association"); Bind(); } }
public void Start(ViewGroup videoContainer, Action <string> callback) { /* * Demonstration of how to record local audio/video to disk while the media stream is active. * * OpusCodec opus = new OpusCodec(); * Vp8Codec vp8 = new Vp8Codec(); * * opus.Initialize(CodecUsage.Encoder, "opus", 48000, 2); * vp8.Initialize(CodecUsage.Encoder, "VP8"); * * var oggPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "audio.ogg"); * var ivfPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "video.ivf"); * * var audioCaptureProvider = new OggAudioCaptureProvider(oggPath, opus); * var videoCaptureProvider = new IvfVideoCaptureProvider(ivfPath, vp8); */ UserMedia.GetMedia(new GetMediaArgs(Audio, Video) { // Uncomment this line to do in-app screen capture. //VideoCaptureProvider = new AndroidScreenCaptureProvider(videoContainer.RootView), VideoWidth = VideoWidth, // optional VideoHeight = VideoHeight, // optional VideoFrameRate = VideoFrameRate, // optional DefaultVideoPreviewScale = LayoutScale.Contain, // optional DefaultVideoScale = LayoutScale.Contain, // optional OnFailure = (e) => { callback(string.Format("Could not get media. {0}", e.Exception.Message)); }, OnSuccess = (e) => { // We have successfully acquired access to the local // audio/video device! Grab a reference to the media. // Internally, it maintains access to the local audio // and video feeds coming from the device hardware. LocalMediaStream = e.LocalStream; // This is our local video control, a View. It is // constantly updated with our live video feed since // we requested video above. Add it directly to the UI // or use the IceLink layout manager, which we do below. var localVideoControl = (View)e.LocalVideoControl; // Create an IceLink layout manager, which makes the task // of arranging video controls easy. Give it a reference // to a View that can be filled with video feeds. if (localVideoControl != null) { LayoutManager = new AndroidLayoutManager(videoContainer); // Position and display the local video control on-screen // by passing it to the layout manager created above. LayoutManager.SetLocalVideoControl(localVideoControl); } callback(null); } }); }
public RedirectToRouteResult BorrowMediaToUser(string name, int userMediaId, IPrincipal user, FormCollection collection) { UserMedia userMedia = UserMediaService.Instance.GetUserMediaById(userMediaId); if (name == null) { string formUsername = collection["TextBoxNameTo"]; if (formUsername.Equals(string.Empty)) { formUsername = collection["User.Friends"]; } UserMediaService.Instance.BorrowUserMediaToUser(formUsername, userMedia); } else { UserMediaService.Instance.BorrowUserMediaToUser(name, userMedia); } if (userMedia.GetType() == typeof(UserMovie)) { return(RedirectToAction("Movie", "Media", new { username = userMedia.User.Username, id = ((UserMovie)userMedia).MovieId })); } else if (userMedia.GetType() == typeof(UserBook)) { return(RedirectToAction("Book", "Media", new { username = userMedia.User.Username, id = ((UserBook)userMedia).BookId })); } else if (userMedia.GetType() == typeof(UserTV_Show)) { return(RedirectToAction("TVShow", "Media", new { username = userMedia.User.Username, id = ((UserTV_Show)userMedia).Season.TV_ShowId })); } else { return(null); } }
public static async Task AddMediaToAlbumAsync( ApplicationDbContext dbContext, MediaAlbum albumEntity, UserMedia mediaEntity, AddImageToAlbum createRequest) { albumEntity.UserMedias.Add(mediaEntity); mediaEntity.MediaAlbum = albumEntity; if (mediaEntity.State == UserMediaState.UploadedButUnused) { mediaEntity.State = UserMediaState.InUse; } mediaEntity.Title = createRequest.Title; if (!string.IsNullOrWhiteSpace(createRequest.Description)) { mediaEntity.Description = await TextOperations.CreateTextAsync( dbContext, createRequest.Description); } await dbContext.SaveChangesAsync(); await SearchOperations.IndexMediaAsync(new[] { mediaEntity }); if (mediaEntity.Description != null) { await UserOperations.NotifyMentionsAsync( dbContext, "Album Entry", mediaEntity.UserId, mediaEntity.Description); } }
public void BorrowUserMediaToUser(string usernameTo, UserMedia media) { BorrowedDetails details = new BorrowedDetails(); details.NameTo = usernameTo; details.BorrowedFromUserId = media.UserId; details.Date = DateTime.Now; details.DateOfReturn = DateTime.MaxValue; details.UserFrom = media.User; details.UserMedia = media; media.MediaStatus = Models.UserMediaStatusEnum.Verborgt.ToString(); try { var request = (from i in media.BorrowRequest where i.UserTo.Equals(usernameTo) select i).Single(); media.BorrowRequest.Remove(request); UserMediaDaoEF.Instance.DeleteBorrowRequest(request); } catch (Exception) { } Save(); }
public static void ClassInitialize(TestContext testContext) { UserMedia1 = new UserMedia("test") { StorageFormat = "Test", Type = "Test" }; }
public async Task <TableResult> InsertAsync(UserMedia entity, CancellationToken ct = default(CancellationToken)) { var insertOperation = TableOperation.Insert(entity); ICancellableAsyncResult ar = _cloudTable.BeginExecute(insertOperation, null, null); ct.Register(ar.Cancel); return(await Task.Factory.FromAsync <TableResult>(ar, _cloudTable.EndExecute).ConfigureAwait(false)); }
public void InsertUserMedia_ValidEntity_PresentInTable() { _repo.Insert(UserMedia1); UserMedia returnedEntity = _repo.GetEntity(UserMedia.FormatPartitionKey(UserMedia1.UserId), UserMedia.FormatRowKey(UserMedia1.UserMediaId)); Assert.AreEqual(UserMedia1.UserId, returnedEntity.UserId, "UserId does not match"); Assert.AreEqual(UserMedia1.UserMediaId, returnedEntity.UserMediaId, "Order does not match"); Assert.AreEqual(UserMedia1.StorageFormat, returnedEntity.StorageFormat, "StorageFormat does not match"); Assert.AreEqual(UserMedia1.Type, returnedEntity.Type, "Type does not match"); }
public void InsertUserMediaAsync_ValidEntity_PresentInTable() { Task <TableResult> insertTask = _repo.InsertAsync(UserMedia1); insertTask.Wait(); UserMedia returnedEntity = (UserMedia)insertTask.Result.Result; Assert.IsFalse(insertTask.IsFaulted, "Task is faulted"); Assert.AreEqual(UserMedia1.UserId, returnedEntity.UserId, "UserId does not match"); Assert.AreEqual(UserMedia1.UserMediaId, returnedEntity.UserMediaId, "Order does not match"); Assert.AreEqual(UserMedia1.StorageFormat, returnedEntity.StorageFormat, "StorageFormat does not match"); Assert.AreEqual(UserMedia1.Type, returnedEntity.Type, "Type does not match"); }
public void GetUserMediaAsync_ValidEntity_UserMediaIsInTaskResult() { _repo.Insert(UserMedia1); Task <TableResult> getTask = _repo.GetEntityAsync(UserMedia.FormatPartitionKey(UserMedia1.UserId), UserMedia.FormatRowKey(UserMedia1.UserMediaId)); getTask.Wait(); UserMedia returnedEntity = (UserMedia)getTask.Result.Result; Assert.AreEqual(UserMedia1.UserId, returnedEntity.UserId, "UserId does not match"); Assert.AreEqual(UserMedia1.UserMediaId, returnedEntity.UserMediaId, "Order does not match"); Assert.AreEqual(UserMedia1.StorageFormat, returnedEntity.StorageFormat, "StorageFormat does not match"); Assert.AreEqual(UserMedia1.Type, returnedEntity.Type, "Type does not match"); }
public async Task <IActionResult> SaveProfile(FileInputModel model) { string Message; int code; long UserID = Convert.ToInt64(Request.GetHeader("UserID")); var isUserExist = db.User.Where(u => u.UserID == UserID).FirstOrDefault(); if (isUserExist != null) { code = 200; Message = "Saved"; string subpath = "~/images/userProfiles/"; string fileName = UserID + "_Profile_" + Guid.NewGuid() + ".jpg"; if (model.FileToUpload != null && model.FileToUpload.Count > 0) { foreach (IFormFile file in model.FileToUpload) { var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot/images/userProfiles/", fileName); using (var stream = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(stream); } UserMedia currentUerMedia = new UserMedia(); currentUerMedia.UserID = UserID; currentUerMedia.type = 1; currentUerMedia.ImageUrl = "wwwroot/images/userProfiles/" + fileName; db.UserMedia.Add(currentUerMedia); db.SaveChanges(); } } return(Ok(new { code, Message })); } else { code = 401; Message = "Login First"; return(Ok(new { code, Message })); } }
public void GetPartitionAsync_InsertEntitiesInTwoPartitions_CorrectAmountOfSegmentsAndCountsReturned() { var userMediaList = new List <UserMedia>(); for (int i = 1; i <= 1050; i++) { var entity = new UserMedia("one") { StorageFormat = "Test", Type = "Test" }; userMediaList.Add(entity); } Task <IList <TableResult> > insertTask = _repo.InsertBatchAsync(userMediaList); insertTask.Wait(); Task <TableQuerySegment <UserMedia> > getResultTask = _repo.GetPartitionAsync(userMediaList[0].PartitionKey); getResultTask.Wait(); var getResult = (TableQuerySegment <UserMedia>)getResultTask.Result; var segmentList = new List <TableQuerySegment <UserMedia> >(); segmentList.Add(getResult); TableContinuationToken cToken = getResult.ContinuationToken; while (cToken != null) { var task = _repo.GetPartitionAsync( userMediaList[0].PartitionKey, cToken ); task.Wait(); segmentList.Add(task.Result); cToken = task.Result.ContinuationToken; } Assert.AreEqual(segmentList.Select(r => r.Results.Count()).Sum(), 1050, "Unexpected result count returned"); Assert.AreEqual(getResult.First().PartitionKey, userMediaList[0].PartitionKey, "Wrong partition key returned"); }
public void DiscardBorrowUserMediaToUser(string usernameTo, UserMedia media) { try { var request = (from i in media.BorrowRequest where i.UserTo.Equals(usernameTo) select i).Single(); media.BorrowRequest.Remove(request); UserMediaDaoEF.Instance.DeleteBorrowRequest(request); } catch (Exception) { } Save(); }
public static async Task <MediaUploadResults> StoreMediaAsync( ApplicationDbContext dbContext, UserInfo userEntity, IEnumerable <UploadedMedia> items) { var newEntities = new List <UserMedia>(); foreach (UploadedMedia item in items) { if (new FileInfo(item.LocalFileName).Length > 0) { string ext = Path.GetExtension(item.OriginalName.Trim('\"')).Substring(1); var entity = new UserMedia { User = userEntity, State = UserMediaState.UploadedButUnused, CreatedUtc = DateTime.UtcNow, Extension = ext }; var dataEntity = new UserMediaData { UserMedia = entity, ImageData = File.ReadAllBytes(item.LocalFileName) }; File.Delete(item.LocalFileName); dbContext.UserMedias.Add(entity); dbContext.UserMediaDatas.Add(dataEntity); newEntities.Add(entity); } } await dbContext.SaveChangesAsync(); await SearchOperations.IndexMediaAsync(newEntities); return(new MediaUploadResults { Files = newEntities .Select( e => new MediaUploadResult { Id = e.UserMediaId }) .ToList() }); }
public void Start(AbsoluteLayout videoContainer, Action <string> callback) { #if __IOS__ AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.PlayAndRecord, AVAudioSessionCategoryOptions.AllowBluetooth | AVAudioSessionCategoryOptions.DefaultToSpeaker); #endif UserMedia.GetMedia(new GetMediaArgs(Audio, Video) { VideoWidth = VideoWidth, // optional VideoHeight = VideoHeight, // optional VideoFrameRate = VideoFrameRate, // optional DefaultVideoPreviewScale = LayoutScale.Contain, // optional DefaultVideoScale = LayoutScale.Contain, // optional OnFailure = (e) => { callback(string.Format("Could not get media. {0}", e.Exception.Message)); }, OnSuccess = (e) => { // We have successfully acquired access to the local // audio/video device! Grab a reference to the media. // Internally, it maintains access to the local audio // and video feeds coming from the device hardware. LocalMediaStream = e.LocalStream; // This is our local video control, a UIView (iOS) or // and NSView (Mac). It is constantly updated with our // live video feed since we requested video above. Add // it directly to the UI or use the IceLink layout manager, // which we do below. var localVideoControl = e.LocalVideoControl; // Create an IceLink layout manager, which makes the task // of arranging video controls easy. Give it a reference // to a UIView that can be filled with video feeds. LayoutManager = new FormsLayoutManager(videoContainer); // Position and display the local video control on-screen // by passing it to the layout manager created above. LayoutManager.SetLocalVideoControl(new FormsVideoControl(localVideoControl)); callback(null); } }); }
public ActionResult <IEnumerable <UserMedia> > UserMedias(string username) { var user = _context.AppUsers.Where(user => user.UserName == username).FirstOrDefault(); var medias = _context.Medias.Where(media => media.AppUserId == user.Id); var countAbonne = _context.UserFollows.Where(uf => uf.AppUserFollowedId == user.Id).Count(); var countAbonnement = _context.UserFollows.Where(uf => uf.AppUserFollowId == user.Id).Count(); var userMedias = new UserMedia { Medias = medias, AppUser = user, CountAbonne = countAbonne, CountAbonnement = countAbonnement, CountMedias = medias.Count() }; return(Ok(userMedias)); // profile component }
private static void ProcessNextPhotoUpload(string username, string origImageUrl, BlobValet blobValet) { var httpClient = new HttpClient(); var origStream = httpClient.GetStreamAsync(origImageUrl).Result; var origMime = blobValet.GetSupportedMimeTypeFromFileName(origImageUrl); var origImage = Image.FromStream(origStream); // create thumb version of image var thumbUrl = BuildThumbnailVersionOfBlobUrl(origImageUrl); var thumbUri = new Uri(thumbUrl); var thumbMime = origMime; #if true var thumbStream = MediaFormatter.PopImageThumbnailer.GetThumbnailStream(origImage, thumbMime); #else var thumb = MediaFormatter.PopImageThumbnailer.GetThumbnail(origImage); thumb.Save(@"d:\temp\foo.png"); var thumbStream = File.Open(@"d:\temp\foo.png", FileMode.Open); #endif #if true blobValet.UploadStream(thumbUri, thumbStream, thumbMime); #else using (var thumbStream2 = new MemoryStream()) { origImage.GetThumbnailImage(100, 100, () => false, IntPtr.Zero).Save(thumbStream2, ImageFormat.Jpeg); thumbStream2.Position = 0; blobValet.UploadStream(thumbUri, thumbStream2); } #endif // now attach it to an account var userMediaRepo = new UserMediaRepository(CloudStorageAccount.DevelopmentStorageAccount, "usermedia"); var userMedia = new UserMedia(username) { StorageFormat = origMime, Url = origImageUrl, ThumbUrl = thumbUrl, UserName = "******" // TODO: << may not want to store this long-term since we have UserId (in SQL Azuregi) }; userMediaRepo.Insert(userMedia); }
/// <summary> /// get media of other user /// </summary> /// <param name="userid">other user's id</param> /// <param name="accesstoken">other user's access token</param> /// <param name="count">media count to retrive</param> /// <param name="max_id">max media id</param> /// <param name="min_id">min media id</param> /// <returns>other user's media</returns> public async Task <UserMedia> User_GetMedia(long userid, string accesstoken, int?count = 0, string max_id = "", string min_id = "") { UserMedia media = new UserMedia(); string URL = _HttpClient.BaseAddress.AbsoluteUri + "users/" + userid.ToString() + "/media/recent/?access_token=" + accesstoken; if (max_id != "") { URL += "&max_id=" + max_id; } if (min_id != "") { URL += "&min_id=" + min_id; } if (count != 0) { URL += "&count=" + count; } try { _ResponseMessage = await _HttpClient.GetAsync(URL); if (_ResponseMessage.IsSuccessStatusCode) { string responsestring = await _ResponseMessage.Content.ReadAsStringAsync(); media = JsonConvert.DeserializeObject <UserMedia>(responsestring); } else { media.meta.code = int.Parse(_ResponseMessage.StatusCode.ToString()); } return(media); } catch (Exception ex) { if (_Telemetryclient != null) { _Telemetryclient.TrackException(ex); } media.meta.code = int.Parse(_ResponseMessage.StatusCode.ToString()); } return(media); }
public IEnumerable <UserMedia> GetUserMediaDetails() { User User = GetSelectedUser(); var selectedPermissions = PermissionsSelector.GetSelectedPermissions(); var UserMediaDetails = new List <UserMedia>(); foreach (Permission permission in selectedPermissions) { var UserMediaDetail = new UserMedia(); UserMediaDetail.DateCreated = UserMediaDetail.DateLastModified = DateTime.Now; UserMediaDetail.UserID = User.ID; UserMediaDetail.PermissionID = permission.ID; UserMediaDetail.MediaID = AdminBasePage.SelectedMedia.ID; UserMediaDetails.Add(UserMediaDetail); } return(UserMediaDetails); }
public PartialViewResult BorrowDetails(int userMediaId) { UserMedia userMedia = UserMediaService.Instance.GetUserMediaById(userMediaId); IQueryable <BorrowedDetails> borrowed = UserMediaService.Instance.GetAllBorrowedAwayMediaByUser(userMedia.User.Username); try { var detail = (from i in borrowed where i.UserMedia.Id == userMediaId && i.DateOfReturn.CompareTo(DateTime.Now) > 0 select i).Single(); BorrowedMediaDetail det = new BorrowedMediaDetail(detail, detail.UserMedia); return(PartialView("../User/ShowBorrowDetails", det)); } catch (Exception) { return(PartialView("../User/ShowBorrowDetails", null)); } }
public static async Task <HttpStatusCode> AddOrRemoveMediaLikeAsync( ApplicationDbContext dbContext, string userId, int mediaId, LikeRequest like) { UserMedia mediaEntity = await dbContext.UserMedias .SingleOrDefaultAsync(te => te.UserMediaId == mediaId); if (mediaEntity == null) { // The entry id is part of the URL, so return a 404. return(HttpStatusCode.NotFound); } return(await LikeOperations.AddOrRemoveLikeAsync( dbContext, userId, mediaId, le => le.UserMediaId, like)); }
public RedirectToRouteResult DiscardBorrowMediaToUser(string name, int userMediaId, IPrincipal user, FormCollection collection) { UserMedia userMedia = UserMediaService.Instance.GetUserMediaById(userMediaId); UserMediaService.Instance.DiscardBorrowUserMediaToUser(name, userMedia); if (userMedia.GetType() == typeof(UserMovie)) { return(RedirectToAction("Movie", "Media", new { username = userMedia.User.Username, id = ((UserMovie)userMedia).MovieId })); } else if (userMedia.GetType() == typeof(UserBook)) { return(RedirectToAction("Book", "Media", new { username = userMedia.User.Username, id = ((UserBook)userMedia).BookId })); } else if (userMedia.GetType() == typeof(UserTV_Show)) { return(RedirectToAction("TVShow", "Media", new { username = userMedia.User.Username, id = ((UserTV_Show)userMedia).Season.TV_ShowId })); } else { return(null); } }
public RedirectToRouteResult SendBorrowRequest(int userMediaId, IPrincipal user) { UserMedia userMedia = UserMediaService.Instance.GetUserMediaById(userMediaId); UserMediaService.Instance.BorrowRequestUserMedia(user.Identity.Name, userMedia); if (userMedia.GetType() == typeof(UserMovie)) { return(RedirectToAction("Movie", "Media", new { username = userMedia.User.Username, id = ((UserMovie)userMedia).MovieId })); } else if (userMedia.GetType() == typeof(UserBook)) { return(RedirectToAction("Book", "Media", new { username = userMedia.User.Username, id = ((UserBook)userMedia).BookId })); } else if (userMedia.GetType() == typeof(UserTV_Show)) { return(RedirectToAction("TVShow", "Media", new { username = userMedia.User.Username, id = ((UserTV_Show)userMedia).Season.TV_ShowId })); } else { return(null); } }