Exemple #1
0
        public IActionResult MakePublish(PublicPrivateSearch search)
        {
            var     query = from ord in _context.SavedSearches where ord.UserId == search.userId && ord.SearchId == search.searchId select ord;
            Boolean res   = false;;

            foreach (SavedSearches ord in query)
            {
                if (ord.IsPublic)
                {
                    ord.IsPublic = false;
                }
                else
                {
                    ord.IsPublic = true;
                }
                res = ord.IsPublic;
            }
            try
            {
                _context.SaveChanges();
                return(Ok(new { data = res }));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(BadRequest());
            }
        }
Exemple #2
0
        private void SetUpClient()
        {
            var builder = new WebHostBuilder()
                          .UseStartup <Startup>()
                          .ConfigureServices(services =>
            {
                var context = new ReportingContext(new DbContextOptionsBuilder <ReportingContext>()
                                                   .UseSqlite("DataSource=:memory:")
                                                   .EnableSensitiveDataLogging()
                                                   .Options);

                services.RemoveAll(typeof(ReportingContext));
                services.AddSingleton(context);

                context.Database.OpenConnection();
                context.Database.EnsureCreated();

                context.SaveChanges();

                // Clear local context cache
                foreach (var entity in context.ChangeTracker.Entries().ToList())
                {
                    entity.State = EntityState.Detached;
                }
            });

            _server = new TestServer(builder);

            Client = _server.CreateClient();
        }
 //[FromBody]
 //Users user
 public IActionResult AddUser([FromBody] Users user)
 {
     try
     {
         if (_context.Users.Any(x => x.Email == user.Email))
         {
             return(BadRequest("Error: There is already User existing with the email entered!"));
         }
         else
         {
             var hashpwd = Encryptdata.MD5Hash(user.Password);
             _context.Users.Add(new Users {
                 Title = user.Title, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Password = hashpwd, Phone = user.Phone, Address = user.Address, IsAdmin = user.IsAdmin, CreationDate = DateTime.Now
             });
             _context.SaveChanges();
             return(Ok("Success"));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest("Error:" + ex.Message));
     }
 }
Exemple #4
0
        public IActionResult AddFilter(SavedSearches filter)
        {
            try
            {
                ReportingContext context = new ReportingContext();
                context.SavedSearches.Add(new SavedSearches {
                    UserId = filter.UserId, Field = filter.Field, Operator1 = filter.Operator1, Operator2 = filter.Operator2, Value1 = filter.Value1, Value2 = filter.Value2, IsPublic = filter.IsPublic, Searchname = filter.Searchname, Logic = filter.Logic
                });
                context.SaveChanges();

                //_context.SavedSearches.Add(new SavedSearches {UserId=filter.UserId, Field = filter.Field, Operator1 = filter.Operator1, Operator2 = filter.Operator2, Value1 = filter.Value1, Value2 = filter.Value2 });
                //_context.SaveChanges();
                return(Ok("Success"));
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
 public void AddTrip(Trip trip)
 {
     _reportingContext.Trips.Add(trip);
     _reportingContext.SaveChanges();
 }
Exemple #6
0
        public async Task <IHttpActionResult> Post([FromBody] HttpHookBuild build)
        {
            var knowDefinitionsBuilds = ConfigurationManager.AppSettings["ExpectedBuilds"].Split('|').Where(i => !string.IsNullOrEmpty(i)).ToArray();

            if (knowDefinitionsBuilds.Any() && !knowDefinitionsBuilds.Contains(build.resource.definition.name))
            {
                return(Ok());
            }

            try
            {
                using (var context = new ReportingContext())
                {
                    var request = build.resource.requests.FirstOrDefault();

                    var buildEntity = new BuildEntity
                    {
                        BuildName          = build.resource.buildNumber,
                        Definition         = build.resource.definition.name,
                        Date               = build.resource.finishTime,
                        Status             = build.resource.status,
                        Reason             = build.resource.reason,
                        Link               = build.message.html,
                        User               = request != null ? request.requestedFor.uniqueName : "Unknown user",
                        CoverageCollection = new Collection <CoverageEntity>()
                    };

                    if (buildEntity.User == "Project Collection Service Accounts")
                    {
                        buildEntity.User = "******";
                    }

                    if (buildEntity.User == ConfigurationManager.AppSettings["VsoUsername"])
                    {
                        return(Ok());
                    }

                    if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["VSO.OrganisationName"]) || string.IsNullOrEmpty(ConfigurationManager.AppSettings["VSO.ProjectName"]))
                    {
                        throw new ApplicationException("Please configuration VSO.OrganisationName and VSO.ProjectName first.");
                    }

                    var api      = new ApiWrapper(ConfigurationManager.AppSettings["VSO.OrganisationName"], ConfigurationManager.AppSettings["VSO.ProjectName"]);
                    var coverage = await api.GetBuildCoverageAsync(build);

                    if (coverage != null)
                    {
                        foreach (var moduleCoverage in coverage)
                        {
                            buildEntity.CoverageCollection.Add(new CoverageEntity
                            {
                                Name             = moduleCoverage.Name,
                                ComputedAverage  = moduleCoverage.ComputedAverage,
                                BlocksCovered    = moduleCoverage.BlocksCovered,
                                BlocksNotCovered = moduleCoverage.BlocksNotCovered,
                                Build            = buildEntity
                            });
                        }
                    }

                    double currentRatio = ComputeRatio(buildEntity, context);
                    var    challenge    = ComputeCoverageChanges(buildEntity, context, currentRatio);
                    if (challenge != null)
                    {
                        context.Challenges.Add(challenge);
                    }

                    context.Builds.Add(buildEntity);
                    context.SaveChanges();
                }

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
 public void AddTrip(Trip trip)
 {
     _reportingContext.Trips.Add(trip);
     _resilientSyncSqlExecutor.Execute(() => _reportingContext.SaveChanges());
 }