public int AddBattery(BatteryModel model)
        {
            var headers = OperationContext.Current.IncomingMessageProperties["httpRequest"];
            var token   = ((HttpRequestMessageProperty)headers).Headers["Token"];

            using (var dbContext = new TokenDbContext())
            {
                ITokenValidator validator = new DatabaseTokenValidator(dbContext);
                if (validator.IsValid(token) == true)
                {
                    using (IDbConnection connection = new SqlConnection(GlobalConfig.CnnString("GyrodataTracker")))
                    {
                        var p = new DynamicParameters();
                        p.Add("@BoxNumber", model.BoxNumber);
                        p.Add("@BatteryCondition", model.BatteryCondition);
                        p.Add("@SerialOne", model.SerialOne);
                        p.Add("@SerialTwo", model.SerialTwo);
                        p.Add("@SerialThr", model.SerialThr);
                        p.Add("@CCD", model.CCD);
                        p.Add("@Invoice", model.Invoice);
                        p.Add("@BatteryStatus", model.BatteryStatus);
                        p.Add("@Arrived", model.Arrived);
                        p.Add("@Container", model.Container);
                        p.Add("@Comment", model.Comment);
                        p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

                        connection.Execute("dbo.spBatteries_Insert", p, commandType: CommandType.StoredProcedure);

                        model.Id = p.Get <int>("@Id");
                    }
                }
            }
            return(model.Id);
        }
Пример #2
0
        public int AddNewItem(ItemModel model)
        {
            var headers = OperationContext.Current.IncomingMessageProperties["httpRequest"];
            var token   = ((HttpRequestMessageProperty)headers).Headers["Token"];

            using (var dbContext = new TokenDbContext())
            {
                ITokenValidator validator = new DatabaseTokenValidator(dbContext);
                if (validator.IsValid(token) == true)
                {
                    using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString("GyrodataTracker")))
                    {
                        var p = new DynamicParameters();
                        p.Add("@Item", model.Item);
                        p.Add("@Asset", model.Asset);
                        p.Add("@Arrived", model.Arrived);
                        p.Add("@Invoice", model.Invoice);
                        p.Add("@CCD", model.CCD);
                        p.Add("@NameRus", model.NameRus);
                        p.Add("@PositionCCD", model.PositionCCD);
                        p.Add("@ItemStatus", model.ItemStatus);
                        p.Add("@Box", model.Box);
                        p.Add("@Container", model.Container);
                        p.Add("@Comment", model.Comment);
                        p.Add("@ItemImage", model.ItemImage);
                        p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

                        connection.Execute("dbo.spItems_Insert", p, commandType: CommandType.StoredProcedure);

                        model.Id = p.Get <int>("@Id");
                    }
                }
            }
            return(model.Id);
        }
        public void EditBattery(string id, BatteryModel model)
        {
            int Id      = int.Parse(id);
            var headers = OperationContext.Current.IncomingMessageProperties["httpRequest"];
            var token   = ((HttpRequestMessageProperty)headers).Headers["Token"];

            using (var dbContext = new TokenDbContext())
            {
                ITokenValidator validator = new DatabaseTokenValidator(dbContext);
                if (validator.IsValid(token) == true)
                {
                    using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString("GyrodataTracker")))
                    {
                        var p = new DynamicParameters();

                        p.Add("@Id", Id);
                        p.Add("@BoxNumber", model.BoxNumber);
                        p.Add("@BatteryCondition", model.BatteryCondition);
                        p.Add("@SerialOne", model.SerialOne);
                        p.Add("@SerialTwo", model.SerialTwo);
                        p.Add("@SerialThr", model.SerialThr);
                        p.Add("@CCD", model.CCD);
                        p.Add("@Invoice", model.Invoice);
                        p.Add("@BatteryStatus", model.BatteryStatus);
                        p.Add("@Arrived", model.Arrived);
                        p.Add("@Container", model.Container);
                        p.Add("@Comment", model.Comment);

                        connection.Execute("spBattery_Update", p, commandType: CommandType.StoredProcedure);
                    }
                }
            }
        }
        public List <BatteryModel> GetSelectedBatteries(string serial, string where)
        {
            List <BatteryModel> batteryList = new List <BatteryModel>();

            var headers = OperationContext.Current.IncomingMessageProperties["httpRequest"];
            var token   = ((HttpRequestMessageProperty)headers).Headers["Token"];

            using (var dbContext = new TokenDbContext())
            {
                ITokenValidator validator = new DatabaseTokenValidator(dbContext);
                if (validator.IsValid(token) == true)
                {
                    using (IDbConnection connection = new SqlConnection(GlobalConfig.CnnString("GyrodataTracker")))
                    {
                        if (connection.State == ConnectionState.Closed)
                        {
                            connection.Open();
                        }

                        var p = new DynamicParameters();

                        p.Add("@SearchWhat", serial);
                        p.Add("@SearchWhere", where);

                        return(connection.Query <BatteryModel>("spGetCustomBatteryData", p, commandType: CommandType.StoredProcedure).ToList());
                    }
                }
                return(null);
            }
        }
 public List <RToken> GetAllToken()
 {
     using (var db = new TokenDbContext())
     {
         return(db.RTokens.ToList());
     }
 }
Пример #6
0
        public void EditItem(string Id, ItemModel model)
        {
            int id      = int.Parse(Id);
            var headers = OperationContext.Current.IncomingMessageProperties["httpRequest"];
            var token   = ((HttpRequestMessageProperty)headers).Headers["Token"];

            using (var dbContext = new TokenDbContext())
            {
                ITokenValidator validator = new DatabaseTokenValidator(dbContext);
                if (validator.IsValid(token) == true)
                {
                    using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString("GyrodataTracker")))
                    {
                        var p = new DynamicParameters();
                        p.Add("@Id", id);
                        p.Add("@ItemItem", model.Item);
                        p.Add("@ItemAsset", model.Asset);
                        p.Add("@ItemArrived", model.Arrived);
                        p.Add("@ItemInvoice", model.Invoice);
                        p.Add("@ItemCCD", model.CCD);
                        p.Add("@ItemNameRus", model.NameRus);
                        p.Add("@PositionCCD", model.PositionCCD);
                        p.Add("@ItemStatus", model.ItemStatus);
                        p.Add("@ItemBox", model.Box);
                        p.Add("@Container", model.Container);
                        p.Add("@Comment", model.Comment);
                        p.Add("@ItemImage", model.ItemImage);

                        connection.Execute("dbo.spUpdate_Item", p, commandType: CommandType.StoredProcedure);
                    }
                }
            }
        }
 public RToken GetToken(string refreshToken, string clientName)
 {
     using (var db = new TokenDbContext())
     {
         return(db.RTokens.FirstOrDefault(x => x.ClientName == clientName && x.RefreshToken == refreshToken));
     }
 }
        // END LOADING DATA FOR JOB CREATION *******

        // Loading Custom Jobs based on what and where
        public List <JobModel> GetCustomJobData(string what, string where)
        {
            var headers = OperationContext.Current.IncomingMessageProperties["httpRequest"];
            var token   = ((HttpRequestMessageProperty)headers).Headers["Token"];

            using (var dbContext = new TokenDbContext())
            {
                ITokenValidator validator = new DatabaseTokenValidator(dbContext);
                if (validator.IsValid(token) == true)
                {
                    using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString("GyrodataTracker")))
                    {
                        if (connection.State == ConnectionState.Closed)
                        {
                            connection.Open();
                        }

                        var p = new DynamicParameters();

                        p.Add("@SearchWhat", what);
                        p.Add("@SearchWhere", where);

                        return(connection.Query <JobModel>("spGetCustomJobData", p, commandType: CommandType.StoredProcedure).ToList());
                        // TODO - remove further
                        //return connection.Query<JobModel>("spGetCustomJobsDataANDROID", p, commandType: CommandType.StoredProcedure).ToList();
                    }
                }
                return(null);
            }
        }
Пример #9
0
        public List <JobModel> GetJobsInvolvedIn(string id)
        {
            var headers = OperationContext.Current.IncomingMessageProperties["httpRequest"];
            var token   = ((HttpRequestMessageProperty)headers).Headers["Token"];

            using (var dbContext = new TokenDbContext())
            {
                ITokenValidator validator = new DatabaseTokenValidator(dbContext);
                if (validator.IsValid(token) == true)
                {
                    using (IDbConnection connection = new SqlConnection(GlobalConfig.CnnString("GyrodataTracker")))
                    {
                        if (connection.State == ConnectionState.Closed)
                        {
                            connection.Open();
                        }

                        var p = new DynamicParameters();

                        p.Add("@ItemId", id);

                        return(connection.Query <JobModel>("spGetJobsInvolvedInData", p, commandType: CommandType.StoredProcedure).ToList());
                    }
                }
                return(null);
            }
        }
        public bool AddToken(RToken token)
        {
            using (var db = new TokenDbContext())
            {
                db.RTokens.Add(token);

                return(db.SaveChanges() > 0);
            }
        }
        public bool ExpireToken(RToken token)
        {
            using (var db = new TokenDbContext())
            {
                db.RTokens.Update(token);

                return(db.SaveChanges() > 0);
            }
        }
Пример #12
0
        private void UpdateDefaultProperties(TokenDbModel dbModel, TokenDbContext dbContext)
        {
            var currentTime = DateTimeOffset.UtcNow;

            dbModel.UpdatedTime = currentTime;
            dbModel.Updater     = dbContext.InstanceId;
            dbModel.CreatedTime = currentTime;
            dbModel.Creator     = dbContext.InstanceId;
        }
        public bool TestToken(string token)
        {
            //var headers = OperationContext.Current.IncomingMessageProperties["httpRequest"];
            //var token = ((HttpRequestMessageProperty)headers).Headers["Token"];

            using (var dbContext = new TokenDbContext())
            {
                ITokenValidator validator = new DatabaseTokenValidator(dbContext);
                return(validator.IsValid(token) ? true : false);
            }
        }
 public string Authenticate(Credentials creds)
 {
     using (var dbContext = new TokenDbContext())
     {
         ICredentialsValidator validator = new DatabaseCredentialsValidator(dbContext);
         if (validator.IsValid(creds))       // pass1 = 63dc4400772b90496c831e4dc2afa4321a4c371075a21feba23300fb56b7e19c
         {
             return(new DatabaseTokenBuilder(dbContext).Build(creds));
         }
         throw new InvalidCredentialException();
     }
 }
Пример #15
0
        public List <string> GetItemsStoring()
        {
            var headers = OperationContext.Current.IncomingMessageProperties["httpRequest"];
            var token   = ((HttpRequestMessageProperty)headers).Headers["Token"];

            using (var dbContext = new TokenDbContext())
            {
                ITokenValidator validator = new DatabaseTokenValidator(dbContext);
                if (validator.IsValid(token) == true)
                {
                    using (IDbConnection connection = new SqlConnection(GlobalConfig.CnnString("GyrodataTracker")))
                    {
                        return(connection.Query <string>("spGetItemsStoring", commandType: CommandType.StoredProcedure).ToList());
                    }
                }
                return(null);
            }
        }
        // Add New Job
        public int AddNewJob(JobModel model)
        {
            var headers = OperationContext.Current.IncomingMessageProperties["httpRequest"];
            var token   = ((HttpRequestMessageProperty)headers).Headers["Token"];

            using (var dbContext = new TokenDbContext())
            {
                ITokenValidator validator = new DatabaseTokenValidator(dbContext);
                if (validator.IsValid(token) == true)
                {
                    using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString("GyrodataTracker")))
                    {
                        var p = new DynamicParameters();
                        p.Add("@JobNumber", model.JobNumber);
                        p.Add("@Client", model.ClientName);
                        p.Add("@GDPAsset", model.GDP);
                        p.Add("@ModemAsset", model.Modem);
                        p.Add("@ModemVersion", model.ModemVersion);
                        p.Add("@BullplugAsset", model.Bullplug);
                        p.Add("@CirculationHours", model.CirculationHours);
                        p.Add("@Battery", model.Battery);
                        p.Add("@MaxTemp", model.MaxTemp);
                        p.Add("@EngineerOne", model.EngineerOne);
                        p.Add("@EngineerTwo", model.EngineerTwo);
                        p.Add("@EngineerOneArrived", model.eng_one_arrived);
                        p.Add("@EngineerTwoArrived", model.eng_two_arrived);
                        p.Add("@EngineerOneLeft", model.eng_one_left);
                        p.Add("@EngineerTwoLeft", model.eng_two_left);
                        p.Add("@Container", model.Container);
                        p.Add("@ContainerArrived", model.ContainerArrived);
                        p.Add("@ContainerLeft", model.ContainerLeft);
                        p.Add("@Rig", model.Rig);
                        p.Add("@Issues", model.Issues);
                        p.Add("@Comment", model.Comment);
                        p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

                        connection.Execute("dbo.spJob_Insert", p, commandType: CommandType.StoredProcedure);

                        model.Id = p.Get <int>("@Id");
                    }
                }
            }
            return(model.Id);
        }
        public void EditJob(string Id, JobModel model)
        {
            int id      = int.Parse(Id);
            var headers = OperationContext.Current.IncomingMessageProperties["httpRequest"];
            var token   = ((HttpRequestMessageProperty)headers).Headers["Token"];

            using (var dbContext = new TokenDbContext())
            {
                ITokenValidator validator = new DatabaseTokenValidator(dbContext);
                if (validator.IsValid(token) == true)
                {
                    using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString("GyrodataTracker")))
                    {
                        var p = new DynamicParameters();

                        p.Add("@Id", id);
                        p.Add("@JobNumber", model.JobNumber);
                        p.Add("@Client", model.ClientName);
                        p.Add("@gdp", model.GDP);
                        p.Add("@modem", model.Modem);
                        p.Add("@ModemVersion", model.ModemVersion);
                        p.Add("@bbp", model.Bullplug);
                        p.Add("@newJobCirculation", model.CirculationHours);
                        p.Add("@Battery", model.Battery);
                        p.Add("@MaxTemp", model.MaxTemp);
                        p.Add("@EngineerOne", model.EngineerOne);
                        p.Add("@EngineerTwo", model.EngineerTwo);
                        p.Add("@EngineerOneArrived", model.eng_one_arrived);
                        p.Add("@EngineerTwoArrived", model.eng_two_arrived);
                        p.Add("@EngineerOneLeft", model.eng_one_left);
                        p.Add("@EngineerTwoLeft", model.eng_two_left);
                        p.Add("@Container", model.Container);
                        p.Add("@ContainerArrived", model.ContainerArrived);
                        p.Add("@ContainerLeft", model.ContainerLeft);
                        p.Add("@Rig", model.Rig);
                        p.Add("@Issues", model.Issues);
                        p.Add("@Comment", model.Comment);

                        connection.Execute("dbo.spUpdate_Job", p, commandType: CommandType.StoredProcedure);
                    }
                }
            }
        }
        public List <List <string> > GetAllDataForJobCreate()
        {
            List <List <string> > initialJobData = new List <List <string> >();

            var headers = OperationContext.Current.IncomingMessageProperties["httpRequest"];
            var token   = ((HttpRequestMessageProperty)headers).Headers["Token"];

            using (var dbContext = new TokenDbContext())
            {
                ITokenValidator validator = new DatabaseTokenValidator(dbContext);
                if (validator.IsValid(token) == true)
                {
                    initialJobData.Add(GetClientsData());
                    initialJobData.Add(GetGdpData());
                    initialJobData.Add(GetModemData());
                    initialJobData.Add(GetBbpData());
                    initialJobData.Add(GetEngineerData());
                    initialJobData.Add(GetBatteriesData());
                }
            }
            return(initialJobData);
        }
Пример #19
0
        //LARAVEL
        public List <ItemModel> GetSelectedItem_lrl(int id)
        {
            var headers = OperationContext.Current.IncomingMessageProperties["httpRequest"];
            var token   = ((HttpRequestMessageProperty)headers).Headers["Token"];

            using (var dbContext = new TokenDbContext())
            {
                ITokenValidator validator = new DatabaseTokenValidator(dbContext);
                if (validator.IsValid(token) == true)
                {
                    using (IDbConnection connection = new SqlConnection(GlobalConfig.CnnString("GyrodataTracker")))
                    {
                        var p = new DynamicParameters();

                        p.Add("@Id", id);

                        return(connection.Query <ItemModel>("spGetSelectedItemData_LRL", p, commandType: CommandType.StoredProcedure).ToList());
                    }
                }
                return(null);
            }
        }
Пример #20
0
 public DatabaseTokenValidator(TokenDbContext dbContext)
 {
     _DbContext = dbContext;
 }
Пример #21
0
 public InMemory(TokenDbContext context)
 {
     _context = context;
 }
Пример #22
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <TokenDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("TokenDb")));

            services.AddCors(corsOptions =>
            {
                corsOptions.AddPolicy("fully permissive", configurePolicy => configurePolicy.AllowAnyHeader().AllowAnyMethod().WithOrigins("http://localhost:4200").AllowCredentials()); //localhost:4200 is the default port an angular runs in dev mode with ng serve
            });

            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <IdentityDbContext>()
            .AddDefaultTokenProviders();

            services.AddDbContext <IdentityDbContext>();
            services.AddScoped <DbContext>(sp => sp.GetService <IdentityDbContext>());

            services.AddAuthentication(options =>
            {
                options.DefaultSignOutScheme   = IdentityConstants.ApplicationScheme;
                options.DefaultSignInScheme    = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = "GitHub";
            })
            .AddCookie()
            .AddGitHub("Github", options =>
            {
                options.ClientId                = "3fa0685e2551a20c0601";
                options.ClientSecret            = "61f60c6c756016aca9b485aba0ab4c81bbe93504";
                options.CallbackPath            = new PathString("/account/HandleExternalLogin");
                options.AuthorizationEndpoint   = "https://github.com/login/oauth/authorize";
                options.TokenEndpoint           = "https://github.com/login/oauth/access_token";
                options.ClaimsIssuer            = "OAuth2-Github";
                options.UserInformationEndpoint = "https://api.github.com/user";
                options.SaveTokens              = true;
                options.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
                options.ClaimActions.MapJsonKey(ClaimTypes.Name, "name");
                options.ClaimActions.MapJsonKey("urn:github:login", "login");
                options.ClaimActions.MapJsonKey("urn:github:url", "html_url");
                options.ClaimActions.MapJsonKey("urn:github:avatar", "avatar_url");
                options.Events = new OAuthEvents
                {
                    OnCreatingTicket = async context =>
                    {
                        var request = new HttpRequestMessage(HttpMethod.Get, context.Options.UserInformationEndpoint);
                        request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                        request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", context.AccessToken);

                        var response = await context.Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, context.HttpContext.RequestAborted);
                        response.EnsureSuccessStatusCode();

                        var user = JObject.Parse(await response.Content.ReadAsStringAsync());

                        context.RunClaimActions(user);
                        using (var ctx = new TokenDbContext())
                        {
                            ctx.TokenDb.Add(new Token {
                                Email = "sanjay", access_Token = context.AccessToken
                            });
                            ctx.SaveChanges();
                        }
                    }
                };
            });


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
Пример #23
0
 public DatabaseCredentialsValidator(TokenDbContext dbContext)
 {
     _DbContext = dbContext;
 }
 public IssueTokenModelsController()
 {
     tokens = new TokenDbContext();
 }
Пример #25
0
 public TokenRepository(TokenDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
 public DatabaseTokenBuilder(TokenDbContext dbContext)
 {
     _DbContext = dbContext;
 }