public async Task <IActionResult> NewPrucess([FromBody] NewIdeaViewModel vm) { if (ModelState.IsValid) { var owner = await userManager.GetUserAsync(HttpContext.User); var idea = await IdeaEx.NewIdea(vm, owner, context, hostingEnvironment); var followers = Follow.Get(owner, context).Result; foreach (Follow track in followers) { Notification.Add(NotificationType.NewPost, track.Owner, owner, idea, context); } await context.SaveChangesAsync(); var titel = Regex.Replace(idea.Titel.ToLower(), @"\s+", "_"); var json = JsonConvert.SerializeObject(new { Id = idea.Id, Name = titel }, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); return(Json(json)); } var JsonData = JsonConvert.SerializeObject(ModelState.Values, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); return(Json(JsonData)); }
public static async Task <Idea> NewIdea(NewIdeaViewModel vm, ApplicationUser owner, IdeasContext context, IHostingEnvironment hostingEnvironment) { var AddThis = Image.GetNewAndRemoveOld(vm.JsonImagesNew, vm.JsonImagesRemove, 0, 0, owner, hostingEnvironment, context).Result; Idea idea = new Idea { Owner = owner, Titel = vm.Titel.Trim(), Text = vm.Text.Trim(), DateTime = DateTime.Now, LatestUpdate = DateTime.Now, Tags = ((vm.JsonTags != null) ? JsonConvert.DeserializeObject <List <Tag> >(vm.JsonTags) : null) }; if (AddThis != null) { AddThis = UnsavedImage.GetList(AddThis.Select(r => r.FileName).ToList(), context, owner); if (idea.Images != null) { foreach (Image image in AddThis) { idea.Images.Add(image); } } else { idea.Images = AddThis; } UnsavedImage.RemoveList(AddThis.Select(r => r.FileName).ToList(), context, owner); } UserStats.AddProject(owner, context); context.Ideas.Add(idea); return(idea); }
public void Reset([FromBody] NewIdeaViewModel model) { try { if (ModelState.IsValid) { string fullPath = Path.Combine(hostingEnvironment.WebRootPath, "images/uploads/"); foreach (var image in model.Images) { var file = string.Format("{0}{1}", fullPath, image.FileName); if (System.IO.File.Exists(file)) { System.IO.File.Delete(file); } } } } catch (Exception e) { var ee = e; } }