Beispiel #1
0
 public IEnumerable <SellerPanelViewModel> GetItems()
 {
     try
     {
         List <SellerPanelViewModel> products = new List <SellerPanelViewModel>();
         IEnumerable <Product>       pr       = (from p in db.Product select p);
         foreach (Product p in pr)
         {
             SellerPanelViewModel sp = new SellerPanelViewModel()
             {
                 id          = p.id,
                 Name        = p.Name,
                 Description = p.Description,
                 Price       = p.Price,
                 Category    = (from c in db.Category
                                where (from pic in db.ProductInCategory
                                       where pic.Product_id == p.id
                                       select pic.Category_id).First() == c.id
                                select c.Name).First()
             };
             products.Add(sp);
         }
         return(products.AsEnumerable());
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message);
         return(null);
     }
 }
Beispiel #2
0
 public SellerPanelViewModel GetItemById(int id)
 {
     try
     {
         Product product         = (from p in db.Product where p.id == id select p).First();
         SellerPanelViewModel pr = new SellerPanelViewModel()
         {
             id          = product.id,
             Name        = product.Name,
             Description = product.Description,
             Price       = product.Price,
             Category    = (from c in db.Category
                            where (from pin in db.ProductInCategory
                                   where pin.Product_id == product.id
                                   select pin.Category_id).First() == c.id
                            select c.Name).First()
         };
         return(pr);
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message);
         return(null);
     }
 }
Beispiel #3
0
        public void SaveChanges(SellerPanelViewModel product)
        {
            try
            {
                Product productToChange = (from p in db.Product where product.id == p.id select p).First();
                productToChange.Name        = product.Name;
                productToChange.Description = product.Description;
                productToChange.Price       = product.Price;
                db.SubmitChanges();

                Product_in_Category changecat = (from c in db.ProductInCategory
                                                 where product.id == c.Product_id
                                                 select c).First();
                changecat.Category_id = (from cat in db.Category
                                         where product.Category == cat.Name
                                         select cat.id).First();
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
        }