public void Delete(int id)
        {
            var album = db.Albums.FirstOrDefault(f => f.AlbumID == id);

            if (album != null)
            {
                db.Entry(album).State = EntityState.Deleted;
            }
            db.SaveChangesAsync();
        }
Ejemplo n.º 2
0
        public void Delete(int id)
        {
            var comment = db.Comments.FirstOrDefault(f => f.CommentID == id);

            if (comment != null)
            {
                db.Entry(comment).State = EntityState.Deleted;
            }
            db.SaveChanges();
        }
Ejemplo n.º 3
0
        public void Delete(int id)
        {
            var photo = db.Photos.FirstOrDefault(f => f.PhotoID == id);

            if (photo != null)
            {
                db.Entry(photo).State = EntityState.Deleted;
            }
            db.SaveChangesAsync();
        }
        public void Delete(string id)
        {
            var clientProfile = db.ClientProfiles.FirstOrDefault(f => f.ClientProfileID.Equals(id));

            if (clientProfile != null)
            {
                db.Entry(clientProfile).State = EntityState.Deleted;
            }
            db.SaveChangesAsync();
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PutPhoto(int id, Photo photo)
        {
            if (id != photo.Id)
            {
                return(BadRequest());
            }

            _context.Entry(photo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PhotoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, AlbumsViewModel model)
        {
            if (id != model.Album.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await UpdateAlbumPhotos(model.Album, model.Photos);

                    _context.Entry(model.Album).State = EntityState.Modified;
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AlbumExists(model.Album.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
Ejemplo n.º 7
0
 public ActionResult Edit([Bind(Include = "Id,Name,Price,CategoryId")] Photo photo)
 {
     if (ModelState.IsValid)
     {
         db.Entry(photo).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(photo));
 }
Ejemplo n.º 8
0
 public ActionResult Edit([Bind(Include = "Id,CartId,PhotoId")] CartItem cartitem)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cartitem).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PhotoId = new SelectList(db.Photos, "Id", "Name", cartitem.PhotoId);
     return(View(cartitem));
 }
Ejemplo n.º 9
0
 public void UpdatePhoto(Photo Photo)
 {
     _dbContext.Entry(Photo).State = EntityState.Modified;
     Save();
 }
Ejemplo n.º 10
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);
                }
            }
        }