예제 #1
0
        //[HttpPost]
        public int Login(string email, string password)
        {
            var dbFactory = new HealthDataContextFactory(
                dataProvider: LinqToDB.DataProvider.MySql.MySqlTools.GetDataProvider(),
                connectionString: _configuration.GetConnectionString("Health")
                );

            using (var context = dbFactory.Create())
            {
                var userquery = (from u in context.Users
                                 where u.Admin == true && u.Email == email && u.Password == password

                                 select u).Take(1);


                foreach (var u in userquery)
                {
                    SetCookie("User", u.Id.ToString(), 20);
                    //HttpContext.Session.Set("User", Encoding.Unicode.GetBytes(usr.Id.ToString()));
                    return(u.Id);
                }
            }
            return(0);
            //return View("Login");

            /*int userId = user.Id;
             * string name = user.Name;
             * string surname = user.Surname;
             * string email = user.Email;
             *
             * return View();*/
        }
예제 #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(options =>
            {
                options.Filters.Add <ValidateModelAttribute>();
            }).AddFluentValidation(fv =>
            {
                fv.RegisterValidatorsFromAssemblyContaining <Startup>();
                fv.RunDefaultMvcValidationAfterFluentValidationExecutes = false;
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info
                {
                    Version        = "v1",
                    Title          = "Health REST APIs",
                    Description    = "REST APIs for health",
                    TermsOfService = "None"
                });

                // Se decommento ottengo un'eccezione quando ho un controller (es. CategoriesController) che estende un altro controller.
                // Set the comments path for the Swagger JSON and UI.
                //var basePath = AppContext.BaseDirectory;
                //var xmlPath = Path.Combine(basePath, "REST.xml");
                //c.IncludeXmlComments(xmlPath);
            });

            services.Configure <Kendo>(Configuration.GetSection("kendo"));
            services.Configure <Theme>(Configuration.GetSection("theme"));

            var dbFactory = new HealthDataContextFactory(
                dataProvider: SQLiteTools.GetDataProvider(),
                connectionString: Configuration.GetConnectionString("Health")
                );

            services.AddSingleton <IDataContextFactory <HealthDataContext> >(dbFactory);
            SetupDatabase(dbFactory);

            services.AddSingleton <IEnumerable <IMenuItem> >(new IMenuItem[]
            {
                new MenuItem {
                    Text = "Categories", Icon = "link", HRef = "/categories"
                },
                new SubMenu
                {
                    Text  = "Multilevel",
                    Items = new[]
                    {
                        new MenuItem {
                            Text = "Link in level 2", Icon = "link", HRef = "#"
                        },
                        new MenuItem {
                            Text = "Link in level 2", Icon = "link", HRef = "#"
                        },
                    }
                }
            });
        }
예제 #3
0
        public User GetUserInformation(int id, IConfiguration _configuration)
        {
            var dbFactory = new HealthDataContextFactory(
                dataProvider: LinqToDB.DataProvider.MySql.MySqlTools.GetDataProvider(),
                connectionString: _configuration.GetConnectionString("Health")
                );

            using (var context = dbFactory.Create())
            {
                IQueryable <User> userQuery =
                    from users in context.Users
                    where users.Id == id
                    select users;

                foreach (var user in userQuery)
                {
                    return(user);
                }
            }
            return(null);
        }
예제 #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);



            var dbFactory = new HealthDataContextFactory(
                dataProvider: LinqToDB.DataProvider.MySql.MySqlTools.GetDataProvider(),
                connectionString: Configuration.GetConnectionString("Health")
                );

            services.AddSingleton <IDataContextFactory <HealthDataContext> >(dbFactory);
            services.AddDistributedMemoryCache(); // Adds a default in-memory implementation of IDistributedCache
            services.AddSession();
            SetupDatabase(dbFactory);
        }