Ejemplo n.º 1
0
        public static int Delete(Guid id)
        {
            try
            {
                using (GroceryGetterEntities dc = new GroceryGetterEntities())
                {
                    tblUserProduct row = dc.tblUserProducts
                                         .FirstOrDefault(up => up.Id == id);

                    if (row != null)
                    {
                        dc.tblUserProducts.Remove(row);
                        return(dc.SaveChanges());
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public static int Update(UserProduct userProduct)
        {
            try
            {
                using (GroceryGetterEntities dc = new GroceryGetterEntities())
                {
                    tblUserProduct tbluserProduct = dc.tblUserProducts.FirstOrDefault(up => up.Id == userProduct.Id);
                    if (tbluserProduct != null)
                    {
                        tbluserProduct.UserId    = userProduct.UserId;
                        tbluserProduct.ProductId = userProduct.ProductId;
                        tbluserProduct.Amount    = userProduct.Amount;
                        tbluserProduct.Notes     = userProduct.Notes;
                        tbluserProduct.InCart    = userProduct.InCart;

                        return(dc.SaveChanges());
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
 public static UserProduct LoadById(Guid id)
 {
     using (GroceryGetterEntities dc = new GroceryGetterEntities())
     {
         tblUserProduct exsitingRow = dc.tblUserProducts.FirstOrDefault(u => u.Id == id);
         if (exsitingRow != null)
         {
             UserProduct uProduct = new UserProduct
             {
                 Id           = exsitingRow.Id,
                 UserId       = exsitingRow.UserId,
                 ProductId    = exsitingRow.ProductId,
                 ProductTitle = exsitingRow.tblProduct.Title,
                 InCart       = exsitingRow.InCart,
                 Amount       = exsitingRow.Amount,
                 Notes        = exsitingRow.Notes,
                 //ProductAisle = exsitingRow.tblAisleProduct.Aisle
             };
             return(uProduct);
         }
         else
         {
             throw new Exception("Row was not found.");
         }
     }
 }
Ejemplo n.º 4
0
        public static int UpdateGroceryList(User user)
        {
            using (GroceryGetterEntities dc = new GroceryGetterEntities())
            {
                tblUser tbluser = dc.tblUsers.FirstOrDefault(u => u.Id == u.Id);

                if (tbluser != null)
                {
                    tbluser.FirstName = user.FirstName;
                    tbluser.LastName  = user.LastName;
                    tbluser.Email     = user.Email;
                    tbluser.UserPass  = user.UserPass;

                    // Delete all the tblUserProduct rows and add back in.
                    var existing = dc.tblUserProducts.Where(up => up.UserId == user.Id);
                    dc.tblUserProducts.RemoveRange(existing);

                    List <tblUserProduct> tblUserProducts = new List <tblUserProduct>();

                    // Also make sense of the tblUserProducts
                    foreach (UserProduct up in user.GroceryList)
                    {
                        tblUserProduct tbluserproduct = new tblUserProduct();
                        tbluserproduct.Id        = Guid.NewGuid();
                        tbluserproduct.UserId    = user.Id;
                        tbluserproduct.ProductId = up.Id;
                        tbluserproduct.InCart    = up.InCart;
                        tbluserproduct.Amount    = up.Amount;
                        tbluserproduct.Notes     = up.Notes;
                        tblUserProducts.Add(tbluserproduct);
                    }

                    dc.tblUserProducts.AddRange(tblUserProducts);

                    int result = dc.SaveChanges();
                    return(result);
                }
                else
                {
                    throw new Exception("Row was not found!!");
                }
            }
        }
Ejemplo n.º 5
0
        public static User LoadByEmail(string email)
        {
            try
            {
                using (GroceryGetterEntities dc = new GroceryGetterEntities())
                {
                    tblUser tbluser = dc.tblUsers.FirstOrDefault(u => u.Email == email);
                    User    user    = new User();

                    if (tbluser != null)
                    {
                        user.Id        = tbluser.Id;
                        user.FirstName = tbluser.FirstName;
                        user.LastName  = tbluser.LastName;
                        user.Email     = tbluser.Email;
                        user.UserPass  = tbluser.UserPass;


                        tblUserProduct tbluserproduct = dc.tblUserProducts.FirstOrDefault(up => up.UserId == user.Id);

                        if (tbluserproduct != null)
                        {
                            user.GroceryList = UserProductManager.LoadByUserId(tbluser.Id);
                        }
                        return(user);
                    }
                    else
                    {
                        throw new Exception("Row was not found!!!!");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 6
0
        public static int Insert(UserProduct userProduct)
        {
            try
            {
                using (GroceryGetterEntities dc = new GroceryGetterEntities())
                {
                    tblUserProduct up = new tblUserProduct();
                    up.Id        = Guid.NewGuid();
                    up.UserId    = userProduct.UserId;
                    up.ProductId = userProduct.ProductId;
                    up.Amount    = userProduct.Amount;
                    up.Notes     = userProduct.Notes;
                    up.InCart    = userProduct.InCart;

                    dc.tblUserProducts.Add(up);

                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }