예제 #1
0
        // GET: /Home/Index
        public ActionResult Index()
        {
            // プロトではタイムラインの先頭から50件を取得する。
            const int pageSize = 50;
            IList<Timeline> timelines = null;
            using (var publisher = new Business.TimelinePublisher())
            {
                timelines = publisher.Subscribe(ctx.CurrentUser.ID, 0, pageSize);
            }

            // マイスレッドは別途取得する。
            var timelines_threadIds = timelines
                .Select(tl => new
                {
                    Timeline = tl,
                    ThreadId = GetThreadIdOrNull(tl)
                });
            var threadIds = timelines_threadIds
                .Where(x => x.ThreadId.HasValue)
                .Select(x => x.ThreadId.Value)
                .ToArray();
            var threadsQuery = db.Threads
                .OfType<PersonalThread>()
                .Where(t => t.OwnerUser.ID == ctx.CurrentUser.ID && threadIds.Contains(t.ID))
                .Include(t => t.Message)
                .Include(t => t.Message.Select(m => m.SentUser));
            LogUtility.DebugWriteQuery(threadsQuery);
            var threads = threadsQuery.ToDictionary(t => t.ID);

            var timelines_threads = timelines_threadIds
                .Select(x => Tuple.Create(x.Timeline, GetThreadOrNull(x.ThreadId, threads)))
                .ToList();

            return View(timelines_threads);
        }
예제 #2
0
        // GET: /Home/Index
        public ActionResult Index()
        {
            // プロトではタイムラインの先頭から50件を取得する。
            const int        pageSize  = 50;
            IList <Timeline> timelines = null;

            using (var publisher = new Business.TimelinePublisher())
            {
                timelines = publisher.Subscribe(ctx.CurrentUser.ID, 0, pageSize);
            }

            // マイスレッドは別途取得する。
            var timelines_threadIds = timelines
                                      .Select(tl => new
            {
                Timeline = tl,
                ThreadId = GetThreadIdOrNull(tl)
            });
            var threadIds = timelines_threadIds
                            .Where(x => x.ThreadId.HasValue)
                            .Select(x => x.ThreadId.Value)
                            .ToArray();
            var threadsQuery = db.Threads
                               .OfType <PersonalThread>()
                               .Where(t => t.OwnerUser.ID == ctx.CurrentUser.ID && threadIds.Contains(t.ID))
                               .Include(t => t.Message)
                               .Include(t => t.Message.Select(m => m.SentUser));

            LogUtility.DebugWriteQuery(threadsQuery);
            var threads = threadsQuery.ToDictionary(t => t.ID);

            var timelines_threads = timelines_threadIds
                                    .Select(x => Tuple.Create(x.Timeline, GetThreadOrNull(x.ThreadId, threads)))
                                    .ToList();

            return(View(timelines_threads));
        }
예제 #3
0
        public ActionResult Create(
            [Bind(Include = "ID,ThreadName")] ProjectThread projectthread,
            [Bind(Include = "From, To")] Duration duration,
            [Bind(Include = "Body")] Message message,
            int?selectAddingUserType,
            string selectedUserIds,
            HttpPostedFileBase uploadedFile)
        {
            if (selectAddingUserType == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            bool userSelected = SetReceivedUser(projectthread, selectAddingUserType, selectedUserIds);

            if (!userSelected)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (!ModelState.IsValid)
            {
                return(View(projectthread));
            }

            // dbフィールドは親クラスのデータベース接続と異なるインスタンスなので、
            // 関係するオブジェクトはAttachしておく必要がある。
            // TODO: あとでdbフィールドを整理
            var currentUser = ctx.CurrentUser as AccountUser;

            db.Users.Attach(currentUser);
            db.Companies.Attach(currentUser.Company);
            db.Projects.Attach(this.Project);

            AttachFile(message, uploadedFile);

            message.Sent = ctx.Now;

            ViewBag.Project = this.Project;

            IQueryable <ProjectGroup> groups = db.Groups.OfType <ProjectGroup>().Where(pg => pg.Project.ID == this.Project.ID);

            ViewBag.ProjectGroups = groups;

            ViewBag.ProjectUsers = db.ParticipantUserProjects.Where(pu => pu.Project.ID == this.Project.ID);

            projectthread.Duration = duration;
            message.SentUser       = db.Users.Find(ctx.CurrentUser.ID);
            projectthread.Message.Add(message);
            projectthread.Project = this.Project;

            db.Threads.Add(projectthread);
            db.SaveChanges();


            // 宛先の参加者のタイムラインを更新する
            // TODO: 非同期処理の検討
            var summary = message.BodySummary;
            var participantsTimeLines = projectthread.ReceivedUsers
                                        .Select(put => put.ParticipantUser)
                                        .Select(pu => new Timeline
            {
                OwnerID         = pu.ID,
                Timestamp       = ctx.Now,
                Type            = TimelineType.ProjectThread,
                SourceName      = "「" + projectthread.Project.Name + "」(" + projectthread.Project.Company.CompanyName + ")",
                Summary         = summary,
                ActionName      = "Messages",
                ControllerName  = "ProjectThread",
                RouteValuesJSON = Timeline.ToJSON(new { projectId = this.Project.ID, threadId = projectthread.ID }),
            });

            using (var publisher = new Business.TimelinePublisher())
            {
                publisher.Publish(participantsTimeLines);
            }

            return(RedirectToAction("Index"));
        }
예제 #4
0
        public ActionResult CreatePersonalThread(string body, HttpPostedFileBase uploadedFile)
        {
            if (string.IsNullOrEmpty(body))
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            // ユーザーのマイページスレッドを新規追加する
            db.Users.Attach(ctx.CurrentUser);

            var newThread = new PersonalThread()
            {
                // マイページスレッドにはスレッド名は不要だが、Required属性がついているため日時を設定しておく。
                ThreadName = ctx.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                // マイページスレッドには期間は不要。
                Duration = null,
                OwnerUser = (ParticipantUser)ctx.CurrentUser
            };
            db.Threads.Add(newThread);
            var newMessage = threadBusiness.AddMessage(newThread, body, uploadedFile);
            try
            {
                db.SaveChanges();
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException ex)
            {
                var es = ex.Entries.ToArray();
                var iex = ex.InnerException as OptimisticConcurrencyException;
                System.Diagnostics.Debugger.Break();
                throw;
            }

            // 自分のおよび友人のタイムラインを更新する
            // TODO: 非同期処理の検討
            var myTimeLine = new Timeline
            {
                OwnerID = ctx.CurrentUser.ID,
                Timestamp = ctx.Now,
                Type = TimelineType.PersonalThread,
                RouteValuesJSON = Timeline.ToJSON(new { threadId = newThread.ID }),
            };
            var friends = new Business.FriendGraph(db)
                .GetFriends(ctx.CurrentUser.ID);
            var summary = newMessage.BodySummary;
            var friendTimeLines = friends.Select(u => new Timeline
            {
                OwnerID = u.ID,
                Timestamp = ctx.Now,
                Type = TimelineType.FriendThread,
                SourceName = ctx.CurrentUser.DisplayName,
                Summary = summary,
                ActionName = "Index",
                ControllerName = "User",
                RouteValuesJSON = Timeline.ToJSON(new { id = ctx.CurrentUser.ID, threadId = newThread.ID }),
            });
            using (var publisher = new Business.TimelinePublisher())
            {
                publisher.Publish(new[] { myTimeLine }.Concat(friendTimeLines));
            }

            return RedirectToAction("Index");
        }
예제 #5
0
        public ActionResult CreatePersonalThread(string body, HttpPostedFileBase uploadedFile)
        {
            if (string.IsNullOrEmpty(body))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            // ユーザーのマイページスレッドを新規追加する
            db.Users.Attach(ctx.CurrentUser);

            var newThread = new PersonalThread()
            {
                // マイページスレッドにはスレッド名は不要だが、Required属性がついているため日時を設定しておく。
                ThreadName = ctx.Now.ToString("yyyy/MM/dd HH:mm:ss"),
                // マイページスレッドには期間は不要。
                Duration  = null,
                OwnerUser = (ParticipantUser)ctx.CurrentUser
            };

            db.Threads.Add(newThread);
            var newMessage = threadBusiness.AddMessage(newThread, body, uploadedFile);

            try
            {
                db.SaveChanges();
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException ex)
            {
                var es  = ex.Entries.ToArray();
                var iex = ex.InnerException as OptimisticConcurrencyException;
                System.Diagnostics.Debugger.Break();
                throw;
            }

            // 自分のおよび友人のタイムラインを更新する
            // TODO: 非同期処理の検討
            var myTimeLine = new Timeline
            {
                OwnerID         = ctx.CurrentUser.ID,
                Timestamp       = ctx.Now,
                Type            = TimelineType.PersonalThread,
                RouteValuesJSON = Timeline.ToJSON(new { threadId = newThread.ID }),
            };
            var friends = new Business.FriendGraph(db)
                          .GetFriends(ctx.CurrentUser.ID);
            var summary         = newMessage.BodySummary;
            var friendTimeLines = friends.Select(u => new Timeline
            {
                OwnerID         = u.ID,
                Timestamp       = ctx.Now,
                Type            = TimelineType.FriendThread,
                SourceName      = ctx.CurrentUser.DisplayName,
                Summary         = summary,
                ActionName      = "Index",
                ControllerName  = "User",
                RouteValuesJSON = Timeline.ToJSON(new { id = ctx.CurrentUser.ID, threadId = newThread.ID }),
            });

            using (var publisher = new Business.TimelinePublisher())
            {
                publisher.Publish(new[] { myTimeLine }.Concat(friendTimeLines));
            }

            return(RedirectToAction("Index"));
        }