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);
            }
        }
        /// <summary>
        /// The landing page is made up of a series of object this returns a list of the collection ojects high level details
        /// </summary>
        /// <param name="email">Users email address</param>
        /// <returns>Returns a list of index model objetcts</returns>
        public List <IndexModel> GetModel(string email)
        {
            List <IndexModel>     model         = new List <IndexModel>();
            List <string>         collectionIds = new List <string>();
            UserCollectionMapping mapping       = new UserCollectionMapping();
            string userId = "";

            try
            {
                FirebaseUser user = new FirebaseUser();
                userId        = user.GetFirebaseUser(email);
                collectionIds = mapping.getCollectionIds(userId, "firebase");
            }
            catch
            {
                AspNetUsers user = new AspNetUsers();
                userId        = user.getUserId(email);
                collectionIds = mapping.getCollectionIds(userId, "asp");
            }
            Collections        collection  = new Collections();
            Account            account     = new Account();
            Budget             budget      = new Budget();
            List <Collections> collections = collection.GetEagerList(collectionIds);

            foreach (Collections item in collections)
            {
                try
                {
                    IndexModel temp = new IndexModel();
                    temp.Name          = item.Name;
                    temp.CollectionsId = item.CollectionsId;
                    temp.Avaialble     = account.GetAvaialable(item.CollectionsId);
                    temp.Budgeted      = Math.Round(budget.GetBudgetedAmount(item.CollectionsId), 2).ToString("N2");
                    temp.Used          = Math.Round(budget.GetSpentAmount(item.CollectionsId), 2).ToString("N2");
                    temp.isShared      = mapping.IsShared(item.CollectionsId);
                    model.Add(temp);
                }
                catch (Exception e)
                {
                    ExceptionCatcher catcher = new ExceptionCatcher();
                    catcher.Catch(e.Message);
                }
            }
            return(model);
        }