/// <summary>
        /// </summary>
        /// <exception cref="ApiException">Thrown when fails to make API call</exception>
        /// <param name="flagID">numeric ID of the flag to get</param>
        /// <param name="body">create a segment under a flag</param>
        /// <returns>Task of ApiResponse (Segment)</returns>
        public async Task <ApiResponse <Segment> > CreateSegmentAsync(long flagID, CreateSegmentRequest body)
        {
            if (body == null)
            {
                throw new ApiException(400, "Missing required parameter 'body' when calling SegmentApi->CreateSegment");
            }

            return(await _httpClient.PostAsync($"flags/{flagID}/segments").WithBody((x) => x.Model(body)).AsApiResponse <Segment>());
        }
Example #2
0
        public async Task <EmptyResponse> Create([FromBody] CreateSegmentRequest model)
        {
            var response = new EmptyResponse();
            var userId   = _userManager.GetUserId(HttpContext.User);

            await _segmentManager.CreateSegmentAsync(userId, model);;

            response.Valid = true;
            return(response);
        }
Example #3
0
        public async Task <Segment> CreateSegmentAsync(string userId, CreateSegmentRequest request)
        {
            using (var dbtr = _db.Database.BeginTransaction())
            {
                try
                {
                    var host = _db.Hosts.FirstOrDefaultAsync(c => c.UserId == userId && request.HostId == c.Id);
                    if (host == null)
                    {
                        return(new Segment());
                    }
                    var newSegment = new Segment()
                    {
                        CreateDate    = DateTime.Now,
                        CreatorId     = userId,
                        HostId        = request.HostId,
                        Paused        = false,
                        IsPublic      = false,
                        ActionId      = request.ActionId,
                        ActionExtra   = request.ActionExtra,
                        AudienceId    = request.AudienceId,
                        AudienceExtra = request.AudienceExtra,
                        SegmentName   = request.SegmentName,
                    };
                    await _db.Segments.AddAsync(newSegment);

                    await _db.SaveChangesAsync();

                    dbtr.Commit();
                    return(newSegment);
                }
                catch
                {
                    dbtr.Rollback();
                    return(new Segment());
                }
            }
        }