Beispiel #1
0
        private void InsertBucketListItem(Shared.dto.BucketListItem bucketListItem, string userName)
        {
            var user = this.context.User
                       .Where(x => x.UserName == userName)
                       .FirstOrDefault();

            if (user == null)
            {
                throw new RecordDoesNotExistException("InsertBucketListItem - User does not exist. UserName: " + userName);
            }

            var bucketListItemToSave = new models.BucketListItem
            {
                ListItemName = bucketListItem.Name,
                Created      = bucketListItem.Created.ToUniversalTime(),
                Category     = bucketListItem.Category,
                Achieved     = bucketListItem.Achieved,
                Latitude     = bucketListItem.Latitude,
                Longitude    = bucketListItem.Longitude
            };

            this.context.BucketListItem.Add(bucketListItemToSave);
            this.context.SaveChanges();

            var bucketListItemUser = new models.BucketListUser
            {
                BucketListItemId = bucketListItemToSave.BucketListItemId,
                UserId           = user.UserId
            };

            this.context.BucketListUser.Add(bucketListItemUser);
            this.context.SaveChanges();
        }
Beispiel #2
0
        private void UpdateBucketListItem
        (
            models.BucketListItem existingBucketListItem,
            Shared.dto.BucketListItem bucketListItem
        )
        {
            existingBucketListItem.ListItemName = bucketListItem.Name;
            existingBucketListItem.Created      = bucketListItem.Created.ToUniversalTime();
            existingBucketListItem.Category     = bucketListItem.Category;
            existingBucketListItem.Achieved     = bucketListItem.Achieved;
            existingBucketListItem.Latitude     = bucketListItem.Latitude;
            existingBucketListItem.Longitude    = bucketListItem.Longitude;

            this.context.Update(existingBucketListItem);
            this.context.SaveChanges();
        }