Exemple #1
0
        public ActionResult Add(int photoId)
        {
            string cartId;

            if (HttpContext.Request.Cookies.AllKeys.Length > 0 &&
                HttpContext.Request.Cookies.AllKeys.Contains("CartId"))
            {
                cartId = HttpContext.Request.Cookies["CartId"].Value;
            }
            else
            {
                cartId = Guid.NewGuid().ToString();
                HttpCookie c = new HttpCookie("CartId", cartId);
                HttpContext.Response.Cookies.Add(c);
            }

            var b = db.ShoppingCarts.Where(c => c.CartId.CompareTo(cartId) == 0 && c.PhotoId == photoId);

            if (!b.Any())
            {
                var item = new CartItem
                {
                    CartId  = cartId,
                    PhotoId = photoId,
                };
                db.ShoppingCarts.Add(item);
            }

            db.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Price,CategoryId")] Photo photo)
        {
            if (ModelState.IsValid)
            {
                db.Photos.Add(photo);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(photo));
        }
Exemple #3
0
        public async Task <IActionResult> CreateImageAsync(Photo photo)
        {
            if (ModelState.IsValid)
            {
                photo.CreatedDate = DateTime.Today;
                if (photo.PhotoAvatar != null && photo.PhotoAvatar.Length > 0)
                {
                    photo.ImageMimeType = photo.PhotoAvatar.ContentType;
                    photo.ImageName     = Path.GetFileName(photo.PhotoAvatar.FileName);
                    using (var memoryStream = new MemoryStream())
                    {
                        photo.PhotoAvatar.CopyTo(memoryStream);
                        photo.PhotoFile = memoryStream.ToArray();
                    }
                    await UploadAsync(photo.PhotoAvatar);


                    _dbContext.Add(photo);
                    _dbContext.SaveChanges();
                    return(RedirectToAction("Index", "Home"));
                }
                return(View(photo));
            }
            return(View(photo));
        }
        public ActionResult Crear(Photo p)
        {
            PhotoContext c = new PhotoContext();

            c.Photos.Add(p);
            c.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult CreatePhoto(Photo photo, HttpPostedFileBase uploadImage)
        {
            if (ModelState.IsValid && uploadImage != null)
            {
                byte[] imageData = null;
                using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                {
                    imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                }
                photo.PhotoSource = imageData;
                db.Photos.Add(photo);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(photo));
        }
        public void SaveUserPhoto(Puzzle.Core.Model.Photo photo)
        {
            Photo dbPhoto = new Photo()
            {
                UserId     = photo.UserId,
                StorageId  = "1234",
                CreateDate = DateTime.Now
            };

            photoContext.Add(dbPhoto);
            photoContext.SaveChanges();
        }
Exemple #7
0
        public ActionResult Create([Bind(Include = "Id,Name,LastName,TotalPrice,Date")] Order orderR)
        {
            if (ModelState.IsValid)
            {
                string cartId;
                if (HttpContext.Request.Cookies.AllKeys.Length > 0 &&
                    HttpContext.Request.Cookies.AllKeys.First(c => c.Contains("CartId")) != null)
                {
                    cartId = HttpContext.Request.Cookies["CartId"].Value;
                    var         items = db.ShoppingCarts.Where(c => c.CartId.CompareTo(cartId) == 0);
                    List <Item> goods = new List <Item>();
                    foreach (var i in items)
                    {
                        var p = db.Photos.Find(i.PhotoId);
                        if (p == null)
                        {
                            continue;
                        }
                        var tm = new Item()
                        {
                            PhotoId = i.PhotoId, ThePhoto = p
                        };
                        goods.Add(tm);
                    }
                    orderR.Items = goods;
                    db.Orders.Add(orderR);

                    var carts = db.ShoppingCarts.Where(x => x.CartId == cartId);
                    db.ShoppingCarts.RemoveRange(carts);
                    db.SaveChanges();
                    HttpContext.Request.Cookies.Remove("CartId");
                }

                return(RedirectToAction("Index", "Home"));
            }

            return(View());
        }
        public void AddPhoto(PhotoViewModel viewmodel)
        {
            //vm -> m
            byte[] picturedata = new byte[viewmodel.PhotoToUpload.Length];
            using (var stream = viewmodel.PhotoToUpload.OpenReadStream())
            {
                stream.Read(picturedata, 0, (int)viewmodel.PhotoToUpload.Length);
            }

            PhotoModel model = new PhotoModel()
            {
                PhotoName   = viewmodel.PhotoName,
                PhotoData   = picturedata,
                ContentType = viewmodel.PhotoToUpload.ContentType
            };

            adatbazis.Photos.Add(model);
            adatbazis.SaveChanges();
        }
Exemple #9
0
 public void Create(Comment item)
 {
     db.Comments.Add(item);
     db.SaveChanges();
 }
 public void Update(Album item)
 {
     db.Entry(item).State = EntityState.Modified;
     db.SaveChanges();
 }
Exemple #11
0
        public static void Initialize(PhotoContext context)
        {
            context.Database.EnsureCreated();

            // If DB contains already labels ==> nothing need to be done
            if (context.Labels.Any())
            {
                return;
            }

            // Initialize labels
            var labels = new Label[]
            {
                new Label {
                    Name = "Daily", Color = "red"
                },
                new Label {
                    Name = "Travel", Color = "blue"
                },
                new Label {
                    Name = "Pet", Color = "green"
                },
                new Label {
                    Name = "Foods", Color = "orange"
                },
                new Label {
                    Name = "Nature", Color = "cyan"
                }
            };

            // Add labels into DB
            foreach (var label in labels)
            {
                context.Labels.Add(label);
            }
            context.SaveChanges();

            // Initialize users
            var users = new User[]
            {
                new User {
                    Username = "******", Password = "******", Role = Role.Admin
                },
                new User {
                    Username = "******", Password = "******", Role = Role.Friend
                },
                new User {
                    Username = "******", Password = "******", Role = Role.Admin
                },
                new User {
                    Username = "******", Password = "******", Role = Role.Visitor
                }
            };

            // Add users into DB
            foreach (var user in users)
            {
                context.Users.Add(user);
            }
            context.SaveChanges();
        }
 public void Update(ClientProfile item)
 {
     db.Entry(item).State = EntityState.Modified;
     db.SaveChanges();
 }
Exemple #13
0
        public static void Seed(PhotoContext db)
        {
            Photographer photographer = new Photographer()
            {
                Username       = "******",
                Email          = "*****@*****.**",
                Password       = "******",
                BirthDate      = new DateTime(1990, 10, 02),
                RegisteredDate = new DateTime(2017, 10, 10)
            };

            Photographer photographerTwo = new Photographer()
            {
                Username       = "******",
                Email          = "*****@*****.**",
                Password       = "******",
                BirthDate      = new DateTime(1989, 09, 02),
                RegisteredDate = new DateTime(2016, 10, 10)
            };

            Photographer photographerThree = new Photographer()
            {
                Username       = "******",
                Email          = "*****@*****.**",
                Password       = "******",
                BirthDate      = new DateTime(1977, 09, 02),
                RegisteredDate = new DateTime(2016, 01, 10)
            };

            Album album = new Album()
            {
                BackgroundColor = "Black",
                IsPublic        = true
            };

            Album albumTwo = new Album()
            {
                BackgroundColor = "White",
                IsPublic        = false
            };

            PhotographerAlbum photographerAlbum = new PhotographerAlbum()
            {
                Album        = album,
                Photographer = photographer
            };

            PhotographerAlbum photographerAlbumTwo = new PhotographerAlbum()
            {
                Album        = album,
                Photographer = photographerTwo
            };

            PhotographerAlbum photographerAlbumThree = new PhotographerAlbum()
            {
                Album        = albumTwo,
                Photographer = photographerTwo
            };

            PhotographerAlbum photographerAlbumFour = new PhotographerAlbum()
            {
                Album        = albumTwo,
                Photographer = photographerThree
            };

            Picture picture = new Picture()
            {
                Caption = "Nature",
                Path    = @"C:\Users\Admin\Desktop\Pictures",
                Title   = "SummerView"
            };

            Picture pictureOne = new Picture()
            {
                Caption = "Animals",
                Path    = @"C:\Users\Admin\Desktop\Pictures",
                Title   = "Zoo"
            };

            Picture pictureTwo = new Picture()
            {
                Caption = "Forest",
                Path    = @"C:\Users\Admin\Desktop\Pictures",
                Title   = "Tree"
            };

            db.PictureAlbums.Add(new PictureAlbum()
            {
                Album   = album,
                Picture = picture
            });

            db.PictureAlbums.Add(new PictureAlbum()
            {
                Album   = album,
                Picture = pictureOne
            });

            db.PictureAlbums.Add(new PictureAlbum()
            {
                Album   = albumTwo,
                Picture = pictureTwo
            });

            db.SaveChanges();
        }
Exemple #14
0
 public void Save()
 {
     _dbContext.SaveChanges();
 }
Exemple #15
0
        static void Main(string[] args)
        {
            //Problema 1
            using (var context = new ModelSelfReferences())
            {
                SelfReference selfReference = new SelfReference()
                {
                    Name = "TRK"
                };
                context.SelfReferences.Add(selfReference);
                context.SaveChanges();

                var items = context.SelfReferences;
                foreach (var x in items)
                {
                    Console.WriteLine(x.Name);
                }
            }

            //Problema 2
            using (var context = new ProductContext())
            {
                var product = new Product
                {
                    SKU         = 150,
                    Description = "Expandable Hydration Pack",
                    Price       = 19.97M,
                    ImageURL    = "/pack147.jpg"
                };
                context.Products.Add(product);
                product = new Product
                {
                    SKU         = 181,
                    Description = "Rugged Ranger Duffel Bag",
                    Price       = 39.97M,
                    ImageURL    = "/pack178.jpg"
                };
                context.Products.Add(product);
                product = new Product
                {
                    SKU         = 189,
                    Description = "Range Field Pack",
                    Price       = 98.97M,
                    ImageURL    = "/noimage.jp"
                };
                context.Products.Add(product);
                product = new Product
                {
                    SKU         = 205,
                    Description = "Small Deployment Back Pack",
                    Price       = 29.97M,
                    ImageURL    = "/pack202.jpg"
                };
                context.Products.Add(product);
                context.SaveChanges();
            }
            using (var context = new ProductContext())
            {
                foreach (var p in context.Products)
                {
                    Console.WriteLine("{0} {1} {2} {3}", p.SKU, p.Description,
                                      p.Price.ToString("C"), p.ImageURL);
                }
            }

            //Problema 3
            byte[] thumbBits = new byte[100];
            byte[] fullBits  = new byte[2000];
            using (var context = new PhotoContext())
            {
                var photo = new Photograph
                {
                    Title         = "No more corona beer",
                    ThumbnailBits = thumbBits
                };
                var fullImage = new PhotographFullImage
                {
                    HighResolutionBits = fullBits
                };

                photo.PhotographFullImage = fullImage;
                context.Photographs.Add(photo);
                context.SaveChanges();
            }
            using (var context = new PhotoContext())
            {
                foreach (var photo in context.Photographs)
                {
                    Console.WriteLine("Photo: {0}, ThumbnailSize {1} bytes",
                                      photo.Title, photo.ThumbnailBits.Length);
                    // explicitly load the "expensive" entity,
                    context.Entry(photo)
                    .Reference(p => p.PhotographFullImage).Load();
                    Console.WriteLine("Full Image Size: {0} bytes",
                                      photo.PhotographFullImage.HighResolutionBits.Length);
                }
            }

            //Problema 4
            using (var context = new BusinessContext())
            {
                var business = new Business
                {
                    Name          = "Corner Dry Cleaning",
                    LicenseNumber = "100x1"
                };
                context.Businesses.Add(business);
                var retail = new Retail
                {
                    Name          = "Shop and Save",
                    LicenseNumber = "200C",
                    Address       = "101 Main",
                    City          = "Anytown",
                    State         = "TX",
                    ZIPCode       = "76106"
                };
                context.Businesses.Add(retail);
                var web = new eCommerce
                {
                    Name          = "BuyNow.com",
                    LicenseNumber = "300AB",
                    URL           = "www.buynow.com"
                };
                context.Businesses.Add(web);
                context.SaveChanges();
            }
            using (var context = new BusinessContext())
            {
                Console.WriteLine("\n--- All Businesses ---");
                foreach (var b in context.Businesses)
                {
                    Console.WriteLine("{0} (#{1})", b.Name, b.LicenseNumber);
                }
                Console.WriteLine("\n--- Retail Businesses ---");
                foreach (var r in context.Businesses.OfType <Retail>())
                {
                    Console.WriteLine("{0} (#{1})", r.Name, r.LicenseNumber);
                    Console.WriteLine("{0}", r.Address);
                    Console.WriteLine("{0}, {1} {2}", r.City, r.State, r.ZIPCode);
                }
                Console.WriteLine("\n--- eCommerce Businesses ---");
                foreach (var e in context.Businesses.OfType <eCommerce>())
                {
                    Console.WriteLine("{0} (#{1})", e.Name, e.LicenseNumber);
                    Console.WriteLine("Online address is: {0}", e.URL);
                }
            }
            //Problema 5
            using (var context = new EmployeeContext())
            {
                var fte = new FullTimeEmployee
                {
                    FirstName = "Jane",
                    LastName  =
                        "Doe",
                    Salary = 71500M
                };
                context.Employees.Add(fte);
                fte = new FullTimeEmployee
                {
                    FirstName = "John",
                    LastName  = "Smith",
                    Salary    = 62500M
                };
                context.Employees.Add(fte);
                var hourly = new HourlyEmployee
                {
                    FirstName = "Tom",
                    LastName  =
                        "Jones",
                    Wage = 8.75M
                };
                context.Employees.Add(hourly);
                context.SaveChanges();
            }
            using (var context = new EmployeeContext())
            {
                Console.WriteLine("--- All Employees ---");
                foreach (var emp in context.Employees)
                {
                    bool fullTime = emp is HourlyEmployee ? false : true;
                    Console.WriteLine("{0} {1} ({2})", emp.FirstName, emp.LastName,
                                      fullTime ? "Full Time" : "Hourly");
                }
                Console.WriteLine("--- Full Time ---");
                foreach (var fte in context.Employees.OfType <FullTimeEmployee>())
                {
                    Console.WriteLine("{0} {1}", fte.FirstName, fte.LastName);
                }
                Console.WriteLine("--- Hourly ---");
                foreach (var hourly in context.Employees.OfType <HourlyEmployee>())
                {
                    Console.WriteLine("{0} {1}", hourly.FirstName,
                                      hourly.LastName);
                }
            }
        }
        public JsonResult AddPhoto(string shortName, HttpPostedFileBase photo)
        {
            try
            {
                var b   = new Bitmap(Image.FromStream(photo.InputStream));
                var img = new Image <Rgb, byte>(b);

                var gray = img.Convert <Gray, Byte>();
                FaceClassifier =
                    new CascadeClassifier(Server.MapPath("~/App_Data/") + "haarcascade_frontalface_default.xml");
                var faces = FaceClassifier.DetectMultiScale(gray, 1.1, 2, Size.Empty, new Size(b.Width, b.Height));
                b = CropImage(b, faces.First());

                b = new Bitmap(b, new Size(FaceLenght, FaceLenght));

                var s = new MemoryStream();
                b.Save(s, ImageFormat.Bmp);
                var p = new Photo()
                {
                    Face = new Picture()
                    {
                        Image = s.ToArray()
                    }
                };
                var owner = PhotoContext.People.FirstOrDefault(x => x.ShortName == shortName);
                if (owner == null)
                {
                    int i = PhotoContext.People.Max(x => x.CommonPhotoNumber) + 1;
                    owner = new Person()
                    {
                        ShortName = shortName, CommonPhotoNumber = i
                    };

                    PhotoContext.People.Add(owner);
                    PhotoContext.SaveChanges();
                    p.IsTheBest = true;
                }
                p.OwnerId = owner.Id;
                owner.Faces.Add(p);
                PhotoContext.Photos.Add(p);
                PhotoContext.Pictures.Add(p.Face);
                PhotoContext.SaveChanges();
                if (PhotoContext.Photos.Count(x => true) > 2)
                {
                    Update(p);
                }
                else
                {
                    Train();
                }
                owner = PhotoContext.People.First(x => x.ShortName == shortName);
                var Id = PhotoContext.Photos.Where(x => x.OwnerId == owner.Id).Max(x => x.Id);
                return(Json(Id));
            }
            catch (Exception e)
            {
                return(Json("Лицо не было найдено"));
            }
        }