예제 #1
0
        /// <summary>
        /// Add user and collection to collection mapping table
        /// </summary>
        /// <param name="obj"> New Collection Object containing user eamil as obj.user and collectionsharing id as obj.name</param>
        /// <returns></returns>
        public bool AddUserToCollection(NewCollectionsObj obj)
        {
            // 3 checks
            // 1 - is count == 0
            CollectionSharing sharing = ShareCounter(obj.name);
            // 2 - is the user different from the other users-- already mapped into UserCollectionsMapping
            UserCollectionMapping mapping = new UserCollectionMapping(sharing.CollectionId, obj.User);

            if (sharing.count == 0 && mapping.CheckUser())
            {
                // set the counter to +1
                sharing.CountIncrament();
                try
                {
                    using (FinPlannerContext _context = new FinPlannerContext())
                    {
                        _context.Entry(sharing).State = EntityState.Modified;
                        _context.UserCollectionMapping.Add(mapping);
                        _context.SaveChanges();
                    }
                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
 private CollectionSharing ShareCounter(string id)
 {
     using (FinPlannerContext _context = new FinPlannerContext())
     {
         CollectionSharing sharing = _context.CollectionSharing.Find(id);
         return(sharing);
     }
 }
예제 #3
0
 private void SavedCollection(CollectionSharing collectionSharing)
 {
     using (FinPlannerContext _context = new FinPlannerContext())
     {
         _context.CollectionSharing.Add(collectionSharing);
         _context.SaveChanges();
     }
 }