public void AddToList(string activity)
        {
            var bucketlist = new BucketList
            {
                Activity = activity
            };

            bucketListContext.Add(bucketlist);
            bucketListContext.SaveChanges();
        }
Exemple #2
0
        public ActionResult Index(string text, int?id, int bucketId)
        {
            BucketItem bi;

            if (id.HasValue)
            {
                bi      = _context.Items.Include("Bucket").FirstOrDefault(x => x.Id == id.Value);
                bi.Text = text;
                _context.SaveChanges();
            }
            else
            {
                bi         = new BucketItem();
                bi.Text    = text;
                bi.Created = DateTime.Now;
                bi.Bucket  = _context.Buckets.FirstOrDefault(x => x.Id == bucketId);
                _context.Items.Add(bi);
                _context.SaveChanges();
            }
            return(Json(bi.Id));
        }
        public ActionResult ResetPassword(ChangePasswordInfo info)
        {
            var    user        = _context.Users.SingleOrDefault(x => x.ID == guid);
            var    userChanges = user;
            string hash        = SecurePasswordHasher.Hash(info.Password);

            userChanges.PasswordHash = hash;
            _context.Entry(user).CurrentValues.SetValues(userChanges);
            _context.Entry(user).State = System.Data.Entity.EntityState.Modified;
            _context.SaveChanges();
            return(View("PasswordChanged"));
        }
        public BucketListItem CreateListItem([FromBody] BucketListItem item)
        {
            item.ID        = Guid.NewGuid();
            item.Created   = DateTime.Now;
            item.Completed = DateTime.Now;
            var user = _context.Users.SingleOrDefault(x => x.ID == item.UserId);

            UserCreatedItemEvent createdEvent = new UserCreatedItemEvent()
            {
                ItemId = item.ID,
                ID     = Guid.NewGuid(),
                Time   = DateTime.Now,
                Title  = user.Username + " added to their bucket list!",
                UserId = user.ID,
            };

            _context.Items.Add(item);
            _context.UserEvents.Add(createdEvent);

            _context.SaveChanges();

            return(item);
        }
        private User GetUser(MyAppUser fbUser)
        {
            var user = _bucketListContext.Users.Include("Bucket").Include("Bucket.Items").FirstOrDefault(x => x.FacebookId == fbUser.Id);

            if (user == null)
            {
                user                 = new User();
                user.FacebookId      = fbUser.Id;
                user.ProfileImageUrl = fbUser.ProfilePicture.Data.Url;
                user.Bucket          = new Bucket();
                user.Bucket.Items    = new List <BucketItem>();
                _bucketListContext.Users.Add(user);
                _bucketListContext.SaveChanges();
            }
            return(user);
        }