private static List <PubItems> ConvertPubItemResultsToPubItems(List <Get_PubItemsViewModel> results)
 {
     if (results.Count() > 0)
     {
         List <PubItems> pubItems = new List <PubItems>();
         foreach (Get_PubItemsViewModel item in results)
         {
             PubItems Item = ConvertItemResultsToPubItems(item);
             pubItems.Add(Item);
         }
         return(pubItems);
     }
     else
     {
         return(null); //no results returned - user ID dosen't exist in DB so give nothing.
     }
 }
        public PubItems AddPubItem(PubItems model)
        {
            SqlParameter @outputParam = new SqlParameter {
                ParameterName = "@outputParam", SqlDbType = SqlDbType.Int, Direction = ParameterDirection.Output
            };

            Database.ExecuteSqlRaw("EXEC @outputParam=Add_PubItem @ItemName, @ItemType, @ItemPrice, @ItemImagePath, @ItemDescription, @ItemStock, @ItemOnSale",
                                   outputParam,
                                   new SqlParameter("@ItemName", model.ItemName),
                                   new SqlParameter("@ItemType", model.ItemType.ToString()),
                                   new SqlParameter("@ItemPrice", model.ItemPrice),
                                   new SqlParameter("@ItemImagePath", (object)model.ItemImagePath ?? DBNull.Value),
                                   new SqlParameter("@ItemDescription", model.ItemDescription),
                                   new SqlParameter("@ItemStock", (object)model.ItemStock ?? 0),
                                   new SqlParameter("@ItemOnSale", model.ItemOnSale));
            int result = (int)@outputParam.Value; //Item ID is returned.

            if (result > 0)
            {
                model.ItemId = result;
                return(model);
            }
            return(null);
        }
        public bool EditPubItem(PubItems model)
        {
            SqlParameter @outputParam = new SqlParameter {
                ParameterName = "@outputParam", SqlDbType = SqlDbType.Int, Direction = ParameterDirection.Output
            };

            Database.ExecuteSqlRaw("EXEC @outputParam=Update_PubItem @ItemID, @ItemName, @ItemType, @ItemPrice, @ItemImagePath, @ItemDescription, @ItemStock, @ItemOnSale",
                                   outputParam,
                                   new SqlParameter("@ItemID", model.ItemId),
                                   new SqlParameter("@ItemName", model.ItemName),
                                   new SqlParameter("@ItemType", model.ItemType.ToString()),
                                   new SqlParameter("@ItemPrice", model.ItemPrice),
                                   new SqlParameter("@ItemImagePath", (object)model.ItemImagePath ?? DBNull.Value),
                                   new SqlParameter("@ItemDescription", model.ItemDescription),
                                   new SqlParameter("@ItemStock", (object)model.ItemStock ?? DBNull.Value),
                                   new SqlParameter("@ItemOnSale", model.ItemOnSale));
            int result = (int)@outputParam.Value;

            if (result == 1)
            {
                return(true);
            }
            return(false);
        }