Beispiel #1
0
        public async Task <ActionResult> SaveStory(StoryViewModel story)
        {
            try
            {
                story.UserId   = SessionManager.CurrentUser.Id;
                story.PostedOn = DateTime.Now;
                var _story = Mapper.Map <StoryViewModel, Story>(story);
                story.Id = await StoryService.AddOrEditStory(_story);

                try
                {
                    var _groupsUsers = await GroupService.GetGroupsUsers(story.Groups.Select(x => x.Id));

                    IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <NotificationHub>();
                    hubContext.Clients.Clients(NotificationHub.GetUsersConnections(_groupsUsers.Where(x => x != story.UserId).ToList())).notify(new Notification
                    {
                        FromUser = SessionManager.CurrentUser.Name,
                        StoryId  = story.Id,
                        Body     = $"Posted story in group(s) {string.Join(",", story.Groups.Select(x => x.Name))}"
                    });
                }
                catch (Exception exx)
                {
                    Logger.Error(exx);
                }
                return(Json(new ResponseData {
                    Data = story
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(Json(ResponseData.ErrorDefault));
            }
        }