Exemplo n.º 1
0
            internal static unsafe bool Invoke(IntPtr obj, MediaPlaylist InPlaylist)
            {
                long *p = stackalloc long[] { 0L, 0L, 0L };
                byte *b = (byte *)p;

                *((IntPtr *)(b + 0)) = InPlaylist;
                Main.GetProcessEvent(obj, OpenPlaylist_ptr, new IntPtr(p));;
                return(*((bool *)(b + 8)));
            }
        }
        public async Task <IHttpActionResult> PostAsync([FromBody] MediaPlaylist model, CancellationToken cancellationToken)
        {
            if (model == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                ModelState.Remove("model.ContactId");
                ModelState.Remove("model.Uri");
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var uri         = string.Join("-", ProjectIdentity.Id.ToString("x"), UriUtility.Normalize(model.Name));
            var oldPlaylist = await _services.Media.FindByUriAsync(uri, cancellationToken);

            if (oldPlaylist != null)
            {
                uri = string.Join("-", ProjectIdentity.Id.ToString("x"), Guid.NewGuid().ToString("n"));
            }
            model = new MediaPlaylist
            {
                ContactId   = ProjectIdentity.Id,
                Uri         = uri,
                Name        = model.Name,
                EditMode    = model.EditMode,
                DefaultList = model.DefaultList,
                Published   = true
            };
            await _services.Media.CreateAsync(model, cancellationToken);

            await _services.SaveAsync(cancellationToken);

            return(CreatedAtRoute("Media.Playlists.GetById", new RouteValueDictionary {
                { "id", model.Id }
            }, model));
        }
        public async Task <IHttpActionResult> PutAsync(int id, [FromBody] MediaPlaylist model, CancellationToken cancellationToken)
        {
            if (model == null || !ModelState.IsValid)
            {
                return(BadRequest());
            }
            var playlist = await _services.Media.FindByIdAsync(id, cancellationToken);

            if (playlist == null)
            {
                return(NotFound());
            }

            playlist.Name        = model.Name;
            playlist.DefaultList = model.DefaultList;
            playlist.EditMode    = model.EditMode;

            await _services.Media.UpdateAsync(playlist, cancellationToken);

            await _services.SaveAsync(cancellationToken);

            return(Ok(model));
        }