Esempio n. 1
0
        public ActionResult Create(PickUploadVM pick)
        {
            ApplicationUser currentUser = db.Users.FirstOrDefault(x => x.UserName == User.Identity.Name);

            Pick pi = new Pick
            {
                PostedBy = currentUser,
                PostedOn = DateTime.Now,
                Description = pick.Description,
                PictureUrl = pick.Url,
            };

            if (pick.File != null)
            {
                using (var ms = new MemoryStream())
                {
                    pick.File.InputStream.CopyTo(ms);
                    pi.Image = Pick.ScaleImage(ms.ToArray(), 150, 150);
                }
            }
            else
            {
                pi.Image = pi.GetBytes(pi.PictureUrl);
            }

            db.Picks.Add(pi);
            db.SaveChanges();

            var result = new { Id = pi.Id, Description = pi.Description, PostedOn = pi.PostedOn.ToString(), PostedBy = pi.PostedBy.UserName };

            return Json(result, JsonRequestBehavior.AllowGet);
        }
Esempio n. 2
0
 public ActionResult GetImage(int id)
 {
     var dbRow = db.Picks.Find(id);
     if (dbRow.Image == null)
     {
         Pick noImage = new Pick();
         noImage.Image = noImage.GetBytes("https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTLna360D4lNuRMj_2nBHnO-vtIh9QhpDXJPnfadeaMQEPJbGNoLdSZ4A");
         return File(noImage.Image, "image");
     }
     return File(dbRow.Image, "image");
 }
Esempio n. 3
0
        public ActionResult GetImage(int id)
        {
            var dbRow = db.Picks.Find(id);

            if (dbRow.Image == null)
            {
                Pick noImage = new Pick();
                noImage.Image = noImage.GetBytes("https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTLna360D4lNuRMj_2nBHnO-vtIh9QhpDXJPnfadeaMQEPJbGNoLdSZ4A");
                return(File(noImage.Image, "image"));
            }
            return(File(dbRow.Image, "image"));
        }
Esempio n. 4
0
        public ActionResult Create(PickUploadVM pick)
        {
            ApplicationUser currentUser = db.Users.FirstOrDefault(x => x.UserName == User.Identity.Name);

            Pick pi = new Pick
            {
                PostedBy    = currentUser,
                PostedOn    = DateTime.Now,
                Description = pick.Description,
                PictureUrl  = pick.Url,
            };

            if (pick.File != null)
            {
                using (var ms = new MemoryStream())
                {
                    pick.File.InputStream.CopyTo(ms);
                    pi.Image = Pick.ScaleImage(ms.ToArray(), 150, 150);
                }
            }
            else
            {
                pi.Image = pi.GetBytes(pi.PictureUrl);
            }


            db.Picks.Add(pi);
            db.SaveChanges();


            var result = new { Id = pi.Id, Description = pi.Description, PostedOn = pi.PostedOn.ToString(), PostedBy = pi.PostedBy.UserName };



            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 5
0
        protected override void Seed(pickme.Models.ApplicationDbContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
            var userStore   = new UserStore <ApplicationUser>(context);
            var userManager = new UserManager <ApplicationUser>(userStore);

            if (!(context.Users.Any(u => u.UserName == "*****@*****.**")))
            {
                var userToInsert = new ApplicationUser {
                    UserName = "******"
                };
                userManager.Create(userToInsert, "Abc123!@#");
            }
            if (!(context.Users.Any(u => u.UserName == "*****@*****.**")))
            {
                var userToInsert = new ApplicationUser {
                    UserName = "******"
                };
                userManager.Create(userToInsert, "Abc123!@#");
            }
            if (!(context.Users.Any(u => u.UserName == "*****@*****.**")))
            {
                var userToInsert = new ApplicationUser {
                    UserName = "******"
                };
                userManager.Create(userToInsert, "Abc123!@#");
            }
            if (!context.Picks.Any())
            {
                ApplicationUser poster = context.Users.FirstOrDefault(x => x.UserName == "*****@*****.**");
                Pick            a      = new Pick {
                    PostedOn = DateTime.Now, PictureUrl = "http://gallery.photo.net/photo/6099217-lg.jpg", Description = "Sweet lagoon -Balos beach -Crete.", PostedBy = poster
                };

                poster = context.Users.FirstOrDefault(x => x.UserName == "*****@*****.**");
                Pick b = new Pick {
                    PostedOn = DateTime.Now, PictureUrl = "http://gallery.photo.net/photo/3659572-md.jpg", Description = "House on the Hill", PostedBy = poster
                };

                poster = context.Users.FirstOrDefault(x => x.UserName == "*****@*****.**");
                Pick c = new Pick {
                    PostedOn = DateTime.Now, PictureUrl = "http://gallery.photo.net/photo/6821374-md.jpg", Description = "Invasive TV", PostedBy = poster
                };

                a.Image = a.GetBytes(a.PictureUrl);
                b.Image = b.GetBytes(b.PictureUrl);
                c.Image = b.GetBytes(c.PictureUrl);


                context.Picks.AddOrUpdate(a);
                context.Picks.AddOrUpdate(b);
                context.Picks.AddOrUpdate(c);
            }
        }