コード例 #1
0
        public override bool Execute()
        {
            int numEvents = eventServices.GetAllEvents().Count();
            int numUserProfiles = accountServices.GetAllUserProfiles().Count();

            int eventId = random.Next(1, numEvents);
            int userProfileId = random.Next(1, numUserProfiles);

            CreateCommentModel addCommentModel = new CreateCommentModel();
            addCommentModel.EventId = eventId;
            addCommentModel.UserProfileId = userProfileId;
            addCommentModel.Comment = "OHOHOHO " + Name + " " + DateTime.Now.ToString();

            return commentServices.CreateComment(addCommentModel);
        }
コード例 #2
0
        public bool CreateComment(CreateCommentModel createCommentModel)
        {
            Comment comment = new Comment();
            comment.CommentText = createCommentModel.Comment;
            comment.Timestamp = DateTime.Now;

            Event evt = db.Events.Where(ev => ev.EventId == createCommentModel.EventId).FirstOrDefault();
            UserProfile userProfile = db.UserProfiles.Where(up => up.UserProfileId == createCommentModel.UserProfileId).FirstOrDefault();

            comment.Event = evt;
            comment.UserProfile = userProfile;

            if (comment.Event != null && comment.UserProfile != null)
            {
                db.AddToComments(comment);
                db.SaveChanges();

                return true;
            }
            else
            {
                return false;
            }
        }
コード例 #3
0
 public ActionResult Index(int id, EventCommentViewModel model)
 {
     CreateCommentModel ccm = new CreateCommentModel
     {
         Comment = model.NewComment,
         EventId = id,
         UserProfileId = AccountServices.GetInstance().GetUserByUsername(User.Identity.Name).UserProfile.UserProfileId
     };
     commentServices.CreateComment(ccm);
     return Index(id);
 }