public HttpResponseMessage CampaignAdd(dynamic data)
        {

            try
            {
                string name = data.Name;
                string description = data.Description;
                Orientation orientation = (Orientation)data.Orientation;
                string resolution = data.Resolution;
                Guid screentypeid = data.ScreenTemplate.screenType;

                var template = ScreenTemplate(orientation, resolution);
                var screenType = ScreenType(screentypeid);

                var repository = factory.GetRepository<Repository<Campaigns>>();
                var repositoryChannel = factory.GetRepository<Repository<Channel>>();

                var campaign = new Campaigns()
                {
                    Name = name,
                    Description = description,
                    ScreenTemplate = template,
                };

                var timeline = new Timeline();

                factory.OnTransaction(() =>
                {

                    var channels = screenType.CreateChannels();

                    timeline.AddScreenType(screenType);

                    foreach (var c in channels)
                    {
                        var channel = repositoryChannel.SaveOrUpdate(c);
                        timeline.AddChannels(channel);
                    }

                    // must get channel id:Z                
                    campaign.AddTimeline(timeline);

                    repository.SaveOrUpdate(campaign);

                });

                var response = new HttpResponseMessage(HttpStatusCode.OK);

                response.Content = new JsonContent(new
                {
                    Campaign = campaign.Id,
                });

                return response;
            }
            catch (Exception ex)
            {
                return new HttpResponseMessage(HttpStatusCode.InternalServerError);
            }


        }
        public HttpResponseMessage CampaignsTimelineAdd(dynamic data)
        {

            Guid campaignId = data.Campaign;
            Guid screenTypeId = data.ScreenType;

            var screenType = GetScreenType(screenTypeId);

            var repository = factory.GetRepository<Repository<Campaigns>>();
            var repositoryChannel = factory.GetRepository<Repository<Channel>>();

            var query = repository.GetQueryable();
            var campaign = query.Where(o => o.Id == campaignId)
                                .FirstOrDefault();


            var timeline = new Timeline();

            factory.OnTransaction(() =>
            {

                var channels = screenType.CreateChannels();


                timeline.AddScreenType(screenType);

                foreach (var c in channels)
                {
                    var channel = repositoryChannel.SaveOrUpdate(c);
                    timeline.AddChannels(channel);
                }

                // must get channel id:Z                
                campaign.AddTimeline(timeline);


            });

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            var result = new
            {
                Timeline = timeline.Id
            };

            response.Content = new JsonContent(result);

            return response;
        }
示例#3
0
 public virtual void AddTimeline(Timeline timeline)
 {
     this.Timelines.Add(timeline);
     timeline.Campaign = this;
 }