Esempio n. 1
0
        public void Initialize()
        {
            mock_context    = new Mock <BioioContext>();
            mock_users      = new Mock <DbSet <User> >();
            mock_devices    = new Mock <DbSet <Device> >();
            mock_datapoints = new Mock <DbSet <DataPoint> >();
            mock_routes     = new Mock <DbSet <Route> >();
            mock_images     = new Mock <DbSet <Image> >();
            users           = new List <User>
            {
                new User {
                    UserID   = 1,
                    BaseUser = new ApplicationUser {
                        Id = "1", UserName = "******", Email = "*****@*****.**"
                    },
                },
                new User {
                    UserID   = 1,
                    BaseUser = new ApplicationUser {
                        Id = "2", UserName = "******", Email = "*****@*****.**"
                    },
                }
            };
            devices    = new List <Device>();
            routes     = new List <Route>();
            datapoints = new List <DataPoint>();
            images     = new List <Image>();

            ConnectMocksToDatastore();
            Repo = new BioioRepository(mock_context.Object);
        }
Esempio n. 2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                BioioRepository Repo = new BioioRepository();
                var             user = new ApplicationUser {
                    Name = model.Name, UserName = model.Email, Email = model.Email, Registered = DateTime.Now
                };
                var result = await UserManager.CreateAsync(user, model.Password);


                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    Repo.AddNewUser(user.Id);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Active", "Index"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 3
0
        public void EnsureCanCreateInstanceOfRepo()
        {
            //Arrange
            BioioRepository repository = new BioioRepository();

            //Act

            //Assert
            Assert.IsNotNull(repository);
        }
Esempio n. 4
0
        // GET: AllRoutes/Create
        public String GetUserRoutes()
        {
            List <string>   all_routes_as_strings = new List <string>();
            BioioRepository repo         = new BioioRepository();
            List <Route>    users_routes = repo.GetAllRoutes();

            string output = JsonConvert.SerializeObject(users_routes);

            return(output);
        }
Esempio n. 5
0
        // GET: Active/Create
        public void CreateNewRoute(List <string> datapoints)
        {
            List <DataPoint> cleaned_datapoints = new List <DataPoint>();
            Route            route = new Route();


            for (int k = 0; k < datapoints.Count; k++)
            {
                cleaned_datapoints.Add((new JavaScriptSerializer()).Deserialize <DataPoint>(datapoints[k]));
            }


            route.Coordinates = cleaned_datapoints;
            route.Created     = DateTime.Now;
            BioioRepository repo = new BioioRepository();

            repo.AddNewRoute(route);
            int i = 0;
        }
Esempio n. 6
0
        public string GetCurrentUser()
        {
            var claimsIdentity = User.Identity as ClaimsIdentity;

            if (claimsIdentity != null)
            {
                var userIdClaim = claimsIdentity.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier);

                if (userIdClaim != null)
                {
                    BioioRepository repo = new BioioRepository();
                    //string userUserName = User.Identity.Name;
                    string userIdValue = userIdClaim.Value;
                    User   this_user   = repo.GetUserById(userIdValue);
                    var    my_user     = JsonConvert.SerializeObject(this_user);
                    return(my_user);
                }
            }
            return(null);
        }