예제 #1
0
        public void RemoveWish(Wish wish)
        {
            var dataContext = GetWriteDataContext();

            RepData.Wish wishToBeRemoved = (from w in dataContext.Wishes
                                            where w.WishId == wish.Id
                                            select w).SingleOrDefault();

            dataContext.Wishes.DeleteOnSubmit(wishToBeRemoved);
            dataContext.SubmitChanges();
        }
예제 #2
0
        /// <summary>
        /// Saves the wish.
        /// </summary>
        /// <param name="wish">The saved wish.</param>
        /// <returns></returns>
        public Wish SaveWish(Wish wish)
        {
            var dataContext = GetWriteDataContext();

            wish.Name        = TruncateString(wish.Name, 100);
            wish.Description = TruncateString(wish.Description, 500);
            wish.LinkUrl     = TruncateString(wish.LinkUrl, 255);

            DateTime timeStamp = DateTime.Now;

            var wishToSave = (from w in dataContext.Wishes
                              where w.WishId == wish.Id
                              select w).SingleOrDefault();

            bool createNew = wishToSave == null;

            if (createNew)
            {
                wishToSave = new RepData.Wish();
                dataContext.Wishes.InsertOnSubmit(wishToSave);
                wishToSave.Created = timeStamp;
                wishToSave.Changed = timeStamp;
            }
            else if (!wish.CalledDiffers(wishToSave.TjingedById))
            {             //We don't want to update the change time if the wish was called or uncalled
                wishToSave.Changed = timeStamp;
            }

            wishToSave.Name        = wish.Name;
            wishToSave.Description = wish.Description;
            wishToSave.LinkUrl     = wish.LinkUrl;
            wishToSave.TjingedById = wish.CalledByUser != null ? (int?)wish.CalledByUser.Id : null;
            wishToSave.OwnerId     = wish.Owner.Id;

            dataContext.SubmitChanges();

            Wish savedWish = (Wish)wish.Clone();

            savedWish.Id = wishToSave.WishId;
            if (createNew)
            {
                savedWish.Created = wishToSave.Created;
            }
            savedWish.Changed = wishToSave.Changed;

            return(savedWish);
        }
예제 #3
0
 private void detach_Wishes1(Wish entity)
 {
     this.SendPropertyChanging();
     entity.User1 = null;
 }
예제 #4
0
 private void attach_Wishes1(Wish entity)
 {
     this.SendPropertyChanging();
     entity.User1 = this;
 }