Exemple #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);
            }
        }
        public ReturnModel CreateCollection(NewCollectionsObj obj)
        {
            Collections           col         = new Collections(obj.durationType, obj.name, obj.User, obj.resetDate);
            UserCollectionMapping mapping     = new UserCollectionMapping(col.CollectionsId, obj.User);
            ReturnModel           returnModel = new ReturnModel();

            if (mapping.Id == "999")
            {
                returnModel.result = false;
                return(returnModel);
            }
            try
            {
                using (FinPlannerContext _context = new FinPlannerContext())
                {
                    _context.Collections.Add(col);
                    _context.UserCollectionMapping.Add(mapping);
                    _context.SaveChanges();
                }
                returnModel.result    = true;
                returnModel.returnStr = col.CollectionsId;
                return(returnModel);
            }
            catch (Exception e)
            {
                returnModel.result = false;
                return(returnModel);
            }
        }