public ResultModel AddOrCreateIdea(AddIdeaDto form) { var httpContext = _httpContextAccessor.HttpContext; string userid = httpContext?.User.Claims.Where(s => s.Type == "userid").FirstOrDefault()?.Value; NewIdea newIdea = null; if (form.Id.HasValue) { newIdea = _ideaRepositry.Find(form.Id.Value); newIdea.Title = form.Title; newIdea.Introduce = form.Introduce; newIdea.Graphic = JsonConvert.SerializeObject(form.ContentList); newIdea.Remark = form.Remark; newIdea.ModificationTime = DateTime.Now; _ideaRepositry.Update(newIdea); newIdea.UpdateCommand(newIdea.Id); } else { newIdea = new NewIdea(form.Title, form.Introduce, JsonConvert.SerializeObject(form.ContentList), new Guid(userid), form.Remark); newIdea.RegisterCommand(newIdea.Id); _ideaRepositry.Add(newIdea); } return(new ResultModel(0, newIdea)); }
public List <NewIdea> GetAllIdeas(int limit = 0) { WaitForThrobber(); List <NewIdea> returnList = new List <NewIdea>(); if (!ResultsTable.Element.HasNoContent("No results found for the selected criteria. Please modify your search criteria.", new Options() { Timeout = TimeSpan.FromSeconds(2) })) { return(returnList); } foreach (SnapshotElementScope row in ResultsTable.Element.FindAllXPath(".//tr[td[6]]")) { NewIdea addIdea = new NewIdea(); addIdea.IdeaID = row.FindXPath("td[1]").Text.Trim(); addIdea.IdeaName = new HpgElement(row.FindXPath("td[2]/a")); addIdea.CreatedDate = DateTime.Parse(row.FindXPath("td[5]").Text); addIdea.Department = row.FindXPath("td[3]").Text.Trim(); addIdea.Status = row.FindXPath("td[4]").Text.Trim(); addIdea.UpdatedDate = DateTime.Parse(row.FindXPath("td[6]").Text); addIdea.Action = new HpgElement(row.FindXPath("td[7]//select")); if (row.FindXPath("td[7]/span[.='Imported']", new Options() { Timeout = TimeSpan.FromSeconds(.5) }).Exists()) { if (row.FindXPath("td[7]/span[.='Imported']")["class"] == "ng-hide") { addIdea.CurrentAction = row.FindXPath("td[7]//select").SelectedOption.ToLower(); } } else { addIdea.CurrentAction = row.FindXPath("td[7]//select").SelectedOption.ToLower(); } if (string.IsNullOrEmpty(addIdea.CurrentAction)) { addIdea.CurrentAction = "imported"; } returnList.Add(addIdea); if (returnList.Count >= limit && limit > 0) { break; } } return(returnList); }
//Create or Update internal static Idea CrUpIdea(NewIdea _idea, string email, string id = null) { if (id == null) { id = Guid.NewGuid().ToString(); } else if (!Storage.IdeaExists(id, email)) { throw new AppException(HttpStatusCode.NotFound, $"idea {id} not found"); } var idea = new Idea(id, _idea); Storage.PutIdea(idea, email); return(idea); }
public async Task <bool> AddIdeaAsync(NewIdea newIdea, ApplicationUser user) { var idea = new Idea { Id = Guid.NewGuid(), AuthorId = Guid.NewGuid(), IdeaListId = Guid.NewGuid(), CreatorId = user.Id, IsPublic = true, Title = newIdea.Title, Description = newIdea.Description, CreateTime = DateTimeOffset.Now, UpdateTime = DateTimeOffset.Now }; _context.Ideas.Add(idea); var saveResult = await _context.SaveChangesAsync(); return(saveResult == 1); }
public async Task <IActionResult> AddIdea(NewIdea newIdea) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var currentUser = await _userManager.GetUserAsync(User); if (currentUser == null) { return(Unauthorized()); } var successful = await _ideaItemService.AddIdeaAsync(newIdea, currentUser); if (!successful) { return(BadRequest(new { error = "Unable to add idea." })); } return(Ok()); }
public HttpResponseMessage UpdateIdea(string id, [FromBody] NewIdea idea) { return(Process((email) => Actions.CrUpIdea(idea, email, id), checkLogin: true)); }
public HttpResponseMessage CreateIdea([FromBody] NewIdea idea) { return(Process((email) => Actions.CrUpIdea(idea, email), HttpStatusCode.Created, true)); }