コード例 #1
0
 protected BaseController()
 {
     if (_context == null)
     {
         _context = new LostAndFoundContext();
     }
 }
コード例 #2
0
        public async Task <ActionResult> Lost(LostReportViewModel model)
        {
            var context = new LostAndFoundContext();
            //List<Species> species = await context.Species.ToListAsync();
            //List<Breed> breeds = await context.Breeds.ToListAsync();
            //ViewData["Breed"] = new SelectList(breeds, "Id", "DisplayName");
            //ViewData["Species"] = new SelectList(species, "Id", "DisplayName");
            var mod = model;

            return(View(new LostReportViewModel()));
        }
コード例 #3
0
 private void SeedSpecies(LostAndFoundContext context)
 {
     //context.Species.AddOrUpdate(s=>s.Name,
     //    new Species() { Id = -1, DateCreated = DateTime.Now, DateModified = DateTime.Now, Name = "Unknown", DisplayName = "Unknown", Description = "Unknown", Status = true },
     //    new Species() { Id = 0, DateCreated = DateTime.Now, DateModified = DateTime.Now, Name = "Dog", DisplayName = "Dog", Description = "Dog", Status = true },
     //    new Species() { Id = 1, DateCreated = DateTime.Now, DateModified = DateTime.Now, Name = "Cat", DisplayName = "Cat", Description = "Cat", Status = true },
     //    new Species() { Id = 2, DateCreated = DateTime.Now, DateModified = DateTime.Now, Name = "Horse", DisplayName = "Horse", Description = "Horse", Status = true },
     //    new Species() { Id = 3, DateCreated = DateTime.Now, DateModified = DateTime.Now, Name = "Cattle", DisplayName = "Cattle", Description = "Cattle", Status = true },
     //    new Species() { Id = 4, DateCreated = DateTime.Now, DateModified = DateTime.Now, Name = "Goat", DisplayName = "Goat", Description = "Goat", Status = true },
     //    new Species() { Id = 5, DateCreated = DateTime.Now, DateModified = DateTime.Now, Name = "GuineaPig", DisplayName = "Guinea Pig", Description = "Guinea Pig", Status = true },
     //    new Species() { Id = 6, DateCreated = DateTime.Now, DateModified = DateTime.Now, Name = "Rabbit", DisplayName = "Rabbit", Description = "Rabbit", Status = true },
     //    new Species() { Id = 7, DateCreated = DateTime.Now, DateModified = DateTime.Now, Name = "Bird", DisplayName = "Bird", Description = "Bird", Status = true }
     //    );
 }
コード例 #4
0
        public async Task <ActionResult> ExternalLoginCallback(string returnUrl)
        {
            var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

            if (loginInfo == null)
            {
                return(RedirectToAction("Login"));
            }
            var ext            = AuthenticationManager.GetExternalIdentity(DefaultAuthenticationTypes.ExternalCookie);
            var email          = ext.Claims.First(c => c.Type.EndsWith("emailaddress")).Value;
            var name           = ext.Claims.First(c => c.Type.EndsWith("name")).Value;
            var claims         = ext.Claims.ToList();
            var firstName      = ext.Claims.FirstOrDefault(c => c.Type == "urn:facebook:first_name")?.Value;
            var lastName       = ext.Claims.FirstOrDefault(c => c.Type == "urn:facebook:last_name")?.Value;
            var nameIdentifier = ext.Claims.First(c => c.Type.EndsWith("nameidentifier")).Value;
            var appId          = "347859642290383";
            var appSecret      = "aa9cc43c6a9bce68f5daaee65a28dd99";
            var accessToken    = "";

            using (var client = new HttpClient())
            {
                try
                {
                    accessToken =
                        client.GetAsync(
                            $"https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id={appId}&client_secret={appSecret}")
                        .Result.Content.ReadAsStringAsync()
                        .Result;
                    var token = JsonConvert.DeserializeObject <JToken>(accessToken).ToDynamic();
                    accessToken = token.access_token.ToString();
                }
                catch (Exception e)
                {
                    throw;
                }
            }

            var progileInamgeUrl = string.Empty;

            if (!string.IsNullOrWhiteSpace(accessToken))
            {
                var fb = new Facebook.FacebookClient(accessToken);
                // fb.Version = "v2.5";

                try
                {
                    var response = fb.Get($"{nameIdentifier}/picture",
                                          new { type = "square", height = 520, width = 520, redirect = 0 });
                    progileInamgeUrl = (response as dynamic)?.data?.url;
                    if (progileInamgeUrl == null)
                    {
                        progileInamgeUrl = String.Empty;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
            // Sign in the user with this external login provider if the user already has a login
            var user = await UserManager.FindAsync(loginInfo.Login);

            if (user != null)
            {
                user.ProfilePictureUri = progileInamgeUrl;

                await SignInAsync(user, isPersistent : false);

                LostAndFoundContext context = new LostAndFoundContext();
                var usr = context.Users.FirstOrDefault(u => u.Id == user.Id);
                usr.ProfilePictureUri = progileInamgeUrl;
                usr.FirstName         = firstName;
                usr.Surname           = lastName;
                await context.SaveChangesAsync();

                return(RedirectToLocal(returnUrl));
            }
            else
            {
                // If the user does not have an account, then prompt the user to create an account
                ViewBag.ReturnUrl     = returnUrl;
                ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
                return(View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel {
                    UserName = loginInfo.DefaultUserName
                }));
            }
        }
コード例 #5
0
 protected BaseManager(LostAndFoundContext context)
 {
     Context = context;
 }
コード例 #6
0
        public LookupManager(LostAndFoundContext context)
        {
            var text = CardType.Amex.Name;

            _context = context;
        }
コード例 #7
0
 public CategoryManager(LostAndFoundContext context) : base(context)
 {
 }