public override void SetUp()
        {
            base.SetUp();

            JohnSmith = new UserBuilder()
                        .With(u => u.Email, "*****@*****.**")
                        .With(u => u.UserName, "JohnSmith")
                        .With(u => u.Id, "guid")
                        .BuildAndSave();

            Ad = new RPClassifiedAdBuilder()
                 .With(ad => ad.Title, "This Is a Title")
                 .With(ad => ad.Text, "This is some text. This is some text. This is some text.")
                 .With(ad => ad.YesThemes, "Everything")
                 .With(ad => ad.NoThemes, "rp with pictures")
                 .With(ad => ad.PreferredTimezones, "Anytime")
                 .With(ad => ad.User, JohnSmith)
                 .With(ad => ad.OwnerMembershipId, JohnSmith.Id)
                 .BuildAndSave();

            cmd = new DeleteRPClassifiedAd()
            {
                UserId = JohnSmith.Id, RPClassifiedAdId = Ad.Id
            };
        }
 public void SaveRPClassifiedAd(RPClassifiedAd RPClassifiedAds)
 {
     if (RPClassifiedAds.Id == 0)
     {
         context.RPClassifiedAds.Add(RPClassifiedAds);
     }
     else
     {
         var editMe = context.RPClassifiedAds.Find(RPClassifiedAds.Id);
         if (editMe != null)
         {
             // dbEntry.Name = RPClassifiedAds.Name;
             // dbEntry.Message = RPClassifiedAds.Message;
             // dbEntry.TimeStamp = RPClassifiedAds.TimeStamp;
         }
     }
     context.SaveChanges();
 }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        /// <exception cref="UserNotFoundException"></exception>
        /// <exception cref="RPClassifiedAdLimitException"></exception>
        /// <exception cref="RPClassifiedAdInvalidInputException"></exception>
        public override int Execute(IDataContext context)
        {
            var result = 0;

            ContextQuery = ctx =>
            {
                var query = from q in ctx.AsQueryable <User>()
                            where q.Id == UserId
                            select new { User = q, AdCount = q.RPClassifiedAds.Count() };

                var user = query.SingleOrDefault();

                if (user == null)
                {
                    throw new UserNotFoundException("User with ID {0} could not be found.", UserId)
                          {
                              UserFriendlyError = "You don't exist."
                          };
                }

                if (user.AdCount >= 3)
                {
                    throw new RPClassifiedAdLimitException("User with ID {0} can not create any more ads.", UserId)
                          {
                              UserFriendlyError    = "You already have the maximum number of RP Classified Ads posted per player.",
                              UserFriendlySubError = "Wait a while for old postings to get automatically deleted or delete some of your own yourself.",
                          };
                }

                var ad = RPClassifiedAd.Create(user.User, this);

                ctx.Add(ad);
                ctx.Commit();

                result = ad.Id;
            };

            ExecuteInternal(context);

            return(result);
        }