コード例 #1
0
ファイル: DataMethods.cs プロジェクト: soonertrent/Gyfto
 public DataMethods()
 {
     if (_gyftoListEntities == null)
     {
         _gyftoListEntities = new GyftoListEntities();
     }
 }
コード例 #2
0
ファイル: DataMethods.cs プロジェクト: soonertrent/Gyfto
 /// <summary>
 /// Updates a List Item
 /// </summary>
 /// <param name="updatedItem"></param>
 /// <returns></returns>
 public Item ListItem_UpdateItem(Item updatedItem, string itemPublicKey)
 {
     try
     {
         if (updatedItem != null)
         {
             using (_gyftoListEntities = new GyftoListEntities())
             {
                 var itemToDetach = _gyftoListEntities.Items.Where(i => i.PublicKey == itemPublicKey).FirstOrDefault();
                 _gyftoListEntities.Detach(itemToDetach);
                 _gyftoListEntities.AttachTo("Items", updatedItem);
                 _gyftoListEntities.ObjectStateManager.ChangeObjectState(updatedItem, EntityState.Modified);
                 _gyftoListEntities.SaveChanges();
             }
         }
         else
         {
             throw new Exception(string.Format("Unable to Locate List Item '{0}'", updatedItem.PublicKey));
         }
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("Unable to Update List Item '{0}' - Error: '{1}'", updatedItem.PublicKey, ex.InnerException.ToString()));
     }
     return updatedItem;
 }
コード例 #3
0
ファイル: DataMethods.cs プロジェクト: soonertrent/Gyfto
        /// <summary>
        /// Update's the Active flag of a List Item
        /// </summary>
        /// <param name="itemPublicKey"></param>
        /// <param name="active"></param>
        /// <returns></returns>
        public Item ListItem_UpdateActiveByItemPublicKey(string itemPublicKey, bool active)
        {
            Item updatedItem = null;

            try
            {
                using (_gyftoListEntities = new GyftoListEntities())
                {
                    updatedItem = _gyftoListEntities.Items.Where(i => i.PublicKey == itemPublicKey).FirstOrDefault();
                    if (updatedItem != null)
                    {
                        updatedItem.Active = active;
                        _gyftoListEntities.SaveChanges();
                    }
                    else
                    {
                        throw new Exception(string.Format("Unable to locate List Item '{0}'", itemPublicKey));
                    }
                }

            }
            catch (Exception ex)
            {

                throw new Exception(string.Format("Unable to update List Item '{0}' - Error: '{1}'", itemPublicKey, ex.InnerException.ToString()));
            }

            return updatedItem;
        }
コード例 #4
0
ファイル: DataMethods.cs プロジェクト: soonertrent/Gyfto
        public List<User> ListItem_GetAllConsumersByListItemPublicKey(string listItemPublicKey)
        {
            var rcUsers = new List<User>();

            using (_gyftoListEntities = new GyftoListEntities())
            {
                // First, get the list of all the consumers for the List this Item is associated to
                var currentItem = ListItem_GetByPublicKey(listItemPublicKey);
                var listConsumers = ListShare_GetCoConsumersForListShare(currentItem.List.PublicKey);

                // Cache all the Item Exclusions
                var itemExclusions = ItemExclusion_GetByItemPublicKey(listItemPublicKey);

                // Next, weed out any Item Exclusions
                foreach (var ls in ListShare_GetAllByListItemPublicKey(listItemPublicKey))
                {
                    if (itemExclusions.Where(ie => ie.ListShareID == ls.ListShareID && ie.ItemID == currentItem.ItemID).Count() == 0)
                    {
                        rcUsers.Add(ls.UserConsumer);
                    }
                }
            }

            return rcUsers;
        }
コード例 #5
0
ファイル: DataMethods.cs プロジェクト: soonertrent/Gyfto
        /// <summary>
        /// Returns an ItemShare by it's Public Key
        /// </summary>
        /// <param name="itemSharePublicKey"></param>
        /// <returns></returns>
        public ItemShare ItemShare_GetByPublicKey(string itemSharePublicKey)
        {
            ItemShare rcItemShare;

            try
            {
                using (_gyftoListEntities = new GyftoListEntities())
                {
                    rcItemShare = _gyftoListEntities.ItemShares.Where(i => i.PublicKey == itemSharePublicKey).SingleOrDefault();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return rcItemShare;
        }
コード例 #6
0
ファイル: DataMethods.cs プロジェクト: soonertrent/Gyfto
 public DataMethods(string connStringName)
 {
     _gyftoListEntities = new GyftoListEntities(connStringName);
 }
コード例 #7
0
ファイル: DataMethods.cs プロジェクト: soonertrent/Gyfto
        /// <summary>
        /// Delete's a given ItemShare
        /// </summary>
        /// <param name="itemSharePublicKey"></param>
        /// <returns></returns>
        public bool ItemShare_Delete(string itemSharePublicKey)
        {
            var rc = false;
            try
            {
                using(_gyftoListEntities = new GyftoListEntities())
                {
                    _gyftoListEntities.ItemShares.DeleteObject(_gyftoListEntities.ItemShares.Where(i => i.PublicKey == itemSharePublicKey).SingleOrDefault());
                    _gyftoListEntities.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Unable to delete ItemShare '{0}' - Error: {1}",itemSharePublicKey, ex.InnerException.ToString()));
            }

            return rc;
        }
コード例 #8
0
ファイル: DataMethods.cs プロジェクト: soonertrent/Gyfto
        /// <summary>
        /// Creates a new ItemShare for a given ListShare and Item
        /// </summary>
        /// <param name="listShareID"></param>
        /// <param name="itemID"></param>
        /// <returns></returns>
        public ItemShare ItemShare_Create(int listShareID, int itemID)
        {
            var newItemShare = new ItemShare();
            try
            {
                newItemShare.CreateDate = DateTime.Now;
                newItemShare.PublicKey = GeneratePublicKey();
                newItemShare.ListShareID = listShareID;
                newItemShare.ItemID = itemID;

                using(_gyftoListEntities = new GyftoListEntities())
                {
                    _gyftoListEntities.ItemShares.AddObject(newItemShare);
                    _gyftoListEntities.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Unable to create ItemShare - Error: '{1}'", ex.InnerException.ToString()));
            }

            return newItemShare;
        }
コード例 #9
0
ファイル: DataMethods.cs プロジェクト: soonertrent/Gyfto
        /// <summary>
        /// Updates the Title/Description of a List
        /// </summary>
        /// <param name="listPublicKey"></param>
        /// <param name="newTitle"></param>
        /// <param name="newDescription"></param>
        /// <returns></returns>
        public List List_UpdateList(string listPublicKey, string newTitle, string newDescription)
        {
            List usrList = null;
            using (_gyftoListEntities = new GyftoListEntities())
            {
                try
                {
                    usrList = _gyftoListEntities.Lists.Where(l => l.PublicKey == listPublicKey).FirstOrDefault();

                    if (usrList != null)
                    {
                        usrList.Title = newTitle;
                        usrList.Description = newDescription;

                        _gyftoListEntities.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
            }

            return usrList;
        }
コード例 #10
0
ファイル: DataMethods.cs プロジェクト: soonertrent/Gyfto
 /// <summary>
 /// Gets all Lists by a given UserID
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public List<List> List_GetListByUserID(int id)
 {
     List<List> usrList;
     using (_gyftoListEntities = new GyftoListEntities())
     {
         usrList = _gyftoListEntities.Lists.Include("Items").Include("User").Include("ListShares").Where(l => l.UserID == id).ToList();
     }
     return usrList;
 }