public virtual Block AddBlocks(Block block) { if (null == this.Blocks) this.Blocks = new HashSet<Block>(); block.Channel = this; this.Blocks.Add(block); return block; }
public HttpResponseMessage ChannelBlocksAdd(dynamic data) { var repository = factory.GetRepository<Repository<Channel>>(); var query = repository.GetQueryable(); Guid id_channel = data.Data.Channel; string context = data.Data.Context; try { var channel = query.Where(o => o.Id == id_channel).FirstOrDefault(); JObject collections = data.Data.Collections; if (collections.Count > 0) { foreach (dynamic c in collections) { Guid resourceId = c.Value.ResourceId; int resourceLength = c.Value.Length; factory.OnTransaction(() => { var block = new Block() { Length = resourceLength, Resource = GetResource(resourceId), }; var result = channel.AddBlocks(block); }); } } var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new JsonContent(new { Campaign = channel.Timeline.Campaign.Id, Timeline = channel.Timeline.Id, Channel = channel.Id, }); return response; } catch (Exception ex) { return new HttpResponseMessage(HttpStatusCode.InternalServerError); } }