Ejemplo n.º 1
0
        vwOrder IService1.AddOrder(vwOrder order) // AddOrder
        {
            try
            {
                using (VinylRecordsShopEntities context = new VinylRecordsShopEntities())
                {
                    if (order.OrderID == 0)
                    {   // ZA ADD
                        tblAlbum albumToEdit = (from r in context.tblAlbums where r.AlbumID == order.AlbumID select r).First();
                        //albumToEdit.GenreID = album.GenreID;
                        //albumToEdit.ArtistID = album.ArtistID;
                        //albumToEdit.Title = album.Title;
                        //albumToEdit.Price = album.Price;
                        albumToEdit.Storage -= order.NumberOfPieces;
                        context.Entry(albumToEdit).State = EntityState.Modified;
                        context.SaveChanges();

                        tblOrder newOrder = new tblOrder();
                        newOrder.EmployeeID     = order.EmployeeID;
                        newOrder.AlbumID        = order.AlbumID;
                        newOrder.CustomerID     = order.CustomerID;
                        newOrder.OrderDate      = order.OrderDate;
                        newOrder.TotalPrice     = order.TotalPrice;
                        newOrder.NumberOfPieces = order.NumberOfPieces;
                        context.tblOrders.Add(newOrder);
                        context.SaveChanges();
                        order.OrderID = newOrder.OrderID;
                        return(order);
                    }
                    else
                    {   // ZA EDIT
                        int      numberOfPieces = (int)(from x in context.vwOrders where x.OrderID == order.OrderID select x.NumberOfPieces).First();
                        tblAlbum albumToEdit    = (from r in context.tblAlbums where r.AlbumID == order.AlbumID select r).First();

                        albumToEdit.Storage = (albumToEdit.Storage + numberOfPieces) - order.NumberOfPieces;
                        context.Entry(albumToEdit).State = EntityState.Modified;
                        context.SaveChanges();

                        tblOrder orderToEdit = (from r in context.tblOrders where r.OrderID == order.OrderID select r).First();
                        orderToEdit.EmployeeID     = order.EmployeeID;
                        orderToEdit.AlbumID        = order.AlbumID;
                        orderToEdit.CustomerID     = order.CustomerID;
                        orderToEdit.OrderDate      = order.OrderDate;
                        orderToEdit.TotalPrice     = order.TotalPrice;
                        orderToEdit.NumberOfPieces = order.NumberOfPieces;
                        //orderToEdit.OrderID = order.OrderID;
                        context.Entry(orderToEdit).State = EntityState.Modified;
                        context.SaveChanges();
                        return(order);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
Ejemplo n.º 2
0
 void IService1.DeleteAlbum(int albumID) // DeleteAlbum
 {
     try
     {
         using (VinylRecordsShopEntities context = new VinylRecordsShopEntities())
         {
             tblAlbum albumToDelete = (from r in context.tblAlbums where r.AlbumID == albumID select r).First();
             context.tblAlbums.Remove(albumToDelete);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
Ejemplo n.º 3
0
 // ADD , EDIT I DELETE ZA ALBUM
 vwAlbum IService1.AddAlbum(vwAlbum album) // AddAlbum
 {
     try
     {
         using (VinylRecordsShopEntities context = new VinylRecordsShopEntities())
         {
             if (album.AlbumID == 0)
             {   // ZA ADD
                 tblAlbum newAlbum = new tblAlbum();
                 newAlbum.GenreID  = album.GenreID;
                 newAlbum.ArtistID = album.ArtistID;
                 newAlbum.Title    = album.Title;
                 newAlbum.Price    = album.Price;
                 newAlbum.Storage  = album.Storage;
                 context.tblAlbums.Add(newAlbum);
                 context.SaveChanges();
                 album.AlbumID = newAlbum.AlbumID;
                 return(album);
             }
             else
             {   // ZA EDIT
                 tblAlbum albumToEdit = (from r in context.tblAlbums where r.AlbumID == album.AlbumID select r).First();
                 albumToEdit.GenreID              = album.GenreID;
                 albumToEdit.ArtistID             = album.ArtistID;
                 albumToEdit.Title                = album.Title;
                 albumToEdit.Price                = album.Price;
                 albumToEdit.Storage              = album.Storage;
                 context.Entry(albumToEdit).State = EntityState.Modified;
                 context.SaveChanges();
                 return(album);
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }