예제 #1
0
        public bool UpdateStory(StoryEdit model)
        {
            var entity = _context.Stories.Single(e => e.Id == model.Id && e.AuthorId == _authorId);

            if (model.CategoryName != null)
            {
                entity.CategoryId = (_context.Categories.Single(c => c.Name.ToLower() == model.CategoryName.ToLower())).Id;
            }
            if (model.WriterName != null)
            {
                entity.WriterId = (_context.Writers.Single(w => w.Name.ToLower() == model.WriterName.ToLower())).Id;
            }
            if (model.Title != null)
            {
                entity.Title = model.Title;
            }
            if (model.Body != null)
            {
                entity.Body = model.Body;
            }
            if (model.Location != null)
            {
                entity.Location = model.Location;
            }
            return(_context.SaveChanges() > 0);
        }
예제 #2
0
        public ActionResult StoryEdit(int id)
        {
            var service = CreateArtService();
            var detail  = service.GetArtById(id);
            var model   =
                new StoryEdit
            {
                ArtID = detail.ArtID,
                Title = detail.Title,
                Note  = detail.Note,
            };

            return(View(model));
        }
예제 #3
0
        public IHttpActionResult Put(StoryEdit model)
        {
            var service = CreateStoryService();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!service.UpdateStory(model))
            {
                return(InternalServerError());
            }
            return(Ok($"The story '{model.Title}' has been updated."));
        }
예제 #4
0
        public bool UpdateStory(StoryEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Arts
                    .Single(e => e.ArtID == model.ArtID && e.OwnerID == _userId);
                entity.ArtID = model.ArtID;
                entity.Title = model.Title;
                entity.Note  = model.Note;

                return(ctx.SaveChanges() == 1);
            }
        }
예제 #5
0
        public ActionResult StoryEdit(int id, StoryEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.ArtID != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateArtService();

            if (service.UpdateStory(model))
            {
                TempData["SaveResult"] = "Your Art Information Was Updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your Art Was Not UPDATED.");
            return(View(model));
        }
예제 #6
0
        public static AjaxCallResult LightStory(int storyId, int revisionId, string lightType, string comment)
        {
            AuthenticationData authData = GetAuthenticationDataAndCulture();

            // TODO: Authorize

            Story story = Story.FromIdentity(storyId);

            try
            {
                // Begin by not confirming GREENLIGHTS unless the RevisionId is correct. Work from there.

                string encryptedAuth = authData.Authority.ToEncryptedXml();
                encryptedAuth = Uri.EscapeDataString(encryptedAuth);

                string uri = "ws://fwn-internal:15615/Editing?Notify=false&Auth=" + encryptedAuth;

                using (
                    var socketClient =
                        new WebSocket(uri))
                {
                    socketClient.Connect();
                    StoryEdit newEdit = null;

                    string personString = "#" + authData.CurrentUser.Identity.ToString("N0");
                    if (authData.CurrentUser.Identity == story.CreatedByPersonId)
                    {
                        personString = "Author";
                    }

                    switch (lightType.ToLowerInvariant())
                    {
                    case "comment":
                        newEdit = story.Edit(StoryEditType.Comment, authData.CurrentUser, comment);
                        socketClient.Send("{\"messageType\":\"AddStoryEdit\",\"EditTimestamp\":\"" + DateTime.UtcNow.ToUnix() + "\",\"StoryId\":\"" + story.Identity + "\",\"StoryEditId\":\"" + newEdit.Identity + "\",\"EditType\":\"Comment\",\"Comment\":\"" + comment.Replace("\"", "\\\"") + "\",\"PersonIdString\":\"" + personString + "\"}");

                        break;

                    case "defer":
                        story.Edit(StoryEditType.Defer, authData.CurrentUser);
                        break;

                    case "red":
                        // Ignore revision, just redlight

                        newEdit = story.Edit(StoryEditType.Redlight, authData.CurrentUser, comment);
                        socketClient.Send("{\"messageType\":\"AddStoryEdit\",\"EditTimestamp\":\"" + DateTime.UtcNow.ToUnix() + "\",\"StoryId\":\"" + story.Identity + "\",\"StoryEditId\":\"" + newEdit.Identity + "\",\"EditType\":\"Redlight\",\"Comment\":\"" + comment.Replace("\"", "\\\"") + "\",\"PersonIdString\":\"" + personString + "\"}");
                        if (GetStoryApprovalRating(story) < -3)
                        {
                            newEdit = story.Edit(StoryEditType.Rejected, authData.CurrentUser,
                                                 "Below rejection threshold");
                            story.ChangeState(StoryState.Rejected);
                            socketClient.Send("{\"serverRequest\":\"UpdateQueueCounts\"}");
                            socketClient.Send("{\"messageType\":\"AddStoryEdit\",\"EditTimestamp\":\"" + DateTime.UtcNow.ToUnix() + "\",\"StoryId\":\"" + story.Identity + "\",\"StoryEditId\":\"" + newEdit.Identity + "\",\"EditType\":\"Rejected\",\"Comment\":\"Below rejection threshold\",\"PersonIdString\":\"" + personString + "\"}");
                            socketClient.Send("{\"messageType\":\"StoryStateChange\",\"StoryId\":\"" + story.Identity + "\",\"StateChange\":\"StoryRejected\"}");
                        }

                        break;

                    case "green":
                        if (story.TopicId == 8)
                        {
                            return(new AjaxCallResult
                            {
                                Success = false,
                                DisplayMessage =
                                    "This is a DRAFT story. It cannot be greenlit until taken out of draft mode. Check for placeholders, then move it to a publication-grade topic before greenlighting."
                            });
                        }

                        if (story.RevisionCount > revisionId)
                        {
                            StoryEdits edits = story.Edits;
                            for (int index = story.RevisionCount; index < edits.Count; index++)
                            {
                                if (edits[index].EditType == StoryEditType.Edit)
                                {
                                    // The story was edited after being sent to client; concurrency error, order reload
                                    return(new AjaxCallResult()
                                    {
                                        Success = false, DisplayMessage = "Reload"
                                    });
                                }
                            }
                        }

                        newEdit = story.Edit(StoryEditType.Greenlight, authData.CurrentUser, comment);
                        socketClient.Send("{\"messageType\":\"AddStoryEdit\",\"EditTimestamp\":\"" + DateTime.UtcNow.ToUnix() + "\",\"StoryId\":\"" + story.Identity + "\",\"StoryEditId\":\"" + newEdit.Identity + "\",\"EditType\":\"Greenlight\",\"Comment\":\"\",\"PersonIdString\":\"" + personString + "\"}");
                        if (GetStoryApprovalRating(story) > 2)      // Three people
                        {
                            newEdit = story.Edit(StoryEditType.ToPublishQueue, authData.CurrentUser, "Moved to publication queue");
                            story.ChangeState(StoryState.PublicationQueue);
                            socketClient.Send("{\"serverRequest\":\"UpdateQueueCounts\"}");
                            socketClient.Send("{\"messageType\":\"AddStoryEdit\",\"EditTimestamp\":\"" + DateTime.UtcNow.ToUnix() + "\",\"StoryId\":\"" + story.Identity + "\",\"StoryEditId\":\"" + newEdit.Identity + "\",\"EditType\":\"ToPublishQueue\",\"Comment\":\"Moved to publication queue\",\"PersonIdString\":\"" + personString + "\"}");
                            socketClient.Send("{\"messageType\":\"StoryStateChange\",\"StoryId\":\"" + story.Identity + "\",\"StateChange\":\"ApprovedForPublishing\"}");
                        }

                        break;

                    default:
                        return(new AjaxCallResult
                        {
                            Success = false,
                            DisplayMessage = "Unknown lighting color in call"
                        });
                    }

                    socketClient.Ping(); // causes a small delay
                    socketClient.Close();
                }

                return(new AjaxCallResult {
                    Success = true
                });
            }
            catch (DatabaseConcurrencyException dbException)
            {
                return(new AjaxCallResult {
                    Success = false, DisplayMessage = "Exception thrown:<br/><br/>" + dbException.ToString()
                });
            }
        }
예제 #7
0
        public static AjaxCallResult CommitStoryEdit(int storyId, int revisionId, string countryCode, int topicId, string headline, string body, string sources, string comment, int photoId)
        {
            try
            {
                AuthenticationData authData = GetAuthenticationDataAndCulture();

                headline = Uri.UnescapeDataString(headline);

                headline = headline.Trim();
                if (headline.EndsWith("."))
                {
                    headline = headline.TrimEnd('.');
                }
                headline = headline.Replace(" : ", ": ").Replace(" ?", "?").Replace("  ", " ");

                headline = Uri.EscapeDataString(headline);

                if (string.IsNullOrEmpty(countryCode))
                {
                    countryCode = "--";
                }

                string uri = "ws://fwn-internal:15615/Editing?Notify=false&Auth=" +
                             Uri.EscapeDataString(authData.Authority.ToEncryptedXml());
                using (
                    var socketClient =
                        new WebSocket(uri))
                {
                    socketClient.Connect();

                    if (storyId > 0)
                    {
                        Country country = null;
                        if (countryCode != "--")
                        {
                            country = Country.FromCode(countryCode);
                        }

                        Story     story     = Story.FromIdentity(storyId);
                        StoryEdit storyEdit = story.Edit(StoryEditType.Edit, authData.CurrentUser,
                                                         Topic.FromIdentity(topicId), null,
                                                         country, headline, body, sources.Replace("  ", " ").Trim(), comment, photoId);

                        story = Story.FromIdentity(storyId);  // reload

                        string personString = "#" + authData.CurrentUser.Identity.ToString("N0");
                        if (authData.CurrentUser.Identity == story.CreatedByPersonId)
                        {
                            personString = "Author";
                        }

                        JObject storyEditedNotify = new JObject();
                        storyEditedNotify["messageType"]    = "StoryEdited";
                        storyEditedNotify["StoryId"]        = story.Identity;
                        storyEditedNotify["Headline"]       = headline;
                        storyEditedNotify["Body"]           = body;
                        storyEditedNotify["Sources"]        = story.SourceLinksHtml;
                        storyEditedNotify["TopicGeography"] = story.Topic.Name + ", " + story.GeographyName;

                        socketClient.Send(storyEditedNotify.ToString());
                        socketClient.Ping();
                        socketClient.Send("{\"messageType\":\"AddStoryEdit\",\"EditTimestamp\":\"" + DateTime.UtcNow.ToUnix() + "\",\"StoryId\":\"" + story.Identity +
                                          "\",\"StoryEditId\":\"" + storyEdit.Identity +
                                          "\",\"EditType\":\"Edit\",\"Comment\":\"" + comment.Replace("\"", "\\\"") +
                                          "\",\"PersonIdString\":\"" + personString +
                                          "\"}");

                        story.Unlock(authData.CurrentUser);
                    }
                    else
                    {
                        Story story = Story.Create(headline, body, Topic.FromIdentity(topicId),
                                                   (countryCode == "--" ? 1 : -Country.FromCode(countryCode).Identity), sources,
                                                   authData.CurrentUser);
                        if (photoId > 0)
                        {
                            story.Photo = Photo.FromIdentity(photoId);
                        }
                        socketClient.Send("{\"serverRequest\":\"UpdateQueueCounts\"}");
                        socketClient.Ping();
                        socketClient.Send("{\"messageType\":\"StoryCreated\"}");
                    }

                    socketClient.Ping();
                    socketClient.Close();
                }

                return(new AjaxCallResult {
                    Success = true
                });
            }
            catch (Exception exception)
            {
                return(new AjaxCallResult
                {
                    Success = false,
                    DisplayMessage = "An exception was thrown [CommitStoryEdit]:<br/><br/>" + exception.ToString()
                });
            }
        }
예제 #8
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            // Retrieve Story from db and perform null check
            Story story = db.Stories.Find(id);

            if (story == null)
            {
                return(HttpNotFound());
            }
            // Instantiate new instance of EditStoryCreateModel
            StoryEdit model = new StoryEdit
            {
                // Can set the player name and Id filds of the ViewModel
                StoryId   = story.ID.ToString(),
                StoryName = story.StoryName
            };

            // Retrieve list of story characters from db in order to find the characters that the story belongs to
            var storyCharacters = db.Characters.Where(i => i.Stories.Any(j => j.ID.Equals(story.ID))).ToList();

            //var playerTeams = db.Teams.Where(t => t.Players.Contains(new Player { PlayerId = player.PlayerId })).ToList();

            // Check that playerTeams is not empty
            if (storyCharacters != null)
            {
                // Initialize the array to number of characters in storyCharacters
                string[] storyCharactersIds = new string[storyCharacters.Count];

                // Then, set the value of platerTeams.Count so the for loop doesn't need to work it out every iteration
                int length = storyCharacters.Count;

                // Now loop over each of the playerTeams and store the Id in the playerTeamsId array
                for (int i = 0; i < length; i++)
                {
                    // Note that we employ the ToString() method to convert the Guid to the string
                    storyCharactersIds[i] = storyCharacters[i].ID.ToString();
                }

                // Instantiate the MultiSelectList, plugging in our playerTeamIds array
                MultiSelectList characterList = new MultiSelectList(db.Characters.ToList().OrderBy(i => i.CharName), "ID", "CharName", storyCharactersIds);

                // Now add the teamsList to the Teams property of our EditPlayerViewModel (model)
                model.Characters = characterList;

                // Return the ViewModel
                return(View(model));
            }
            else
            {
                // Else instantiate the teamsList without any pre-selected values
                MultiSelectList characterList = new MultiSelectList(db.Characters.ToList().OrderBy(i => i.CharName), "ID", "CharName");

                // Set the Teams property of the EditPlayerViewModel with the teamsList
                model.Characters = characterList;

                // Return the ViewModel
                return(View(model));
            }
        }