public ActionResult Create() { StoryViewModel model = new StoryViewModel(); TaskResult<IEnumerable<GroupDetail>> groupDetailRequest =groupDataService.GetGroups(new DataRequest { StartPosition = 0, Count = 100 }); if(groupDetailRequest.Data!=null) { model.AllGroups = groupDetailRequest.Data.Select(a => a.ConvertToGroupViewModel()); } return View(model); }
public static StoryDetail ConvertToStoryDetail(this StoryViewModel model) { return(new StoryDetail { Content = model.Content, Description = model.Description, GroupDetails = model.GroupDetails == null?null:model.GroupDetails.Select(a => a.ConvertToGroupDetail()).AsEnumerable(), Id = model.Id, PostedOn = model.PostedOn, Title = model.Title, UserId = model.UserId }); }
public ActionResult Create(StoryViewModel model, int[] selectedItems) { if(model.Title==null)//Invalid Model State, dirty approach { return View(model); } int[] items = selectedItems; if (selectedItems == null) { items = new int[0]; } StoryDetail detail = model.ConvertToStoryDetail(); detail.UserId = UserDetails.Id; detail.GroupDetails = items.Select(a => new GroupDetail { Id = a }); storyDataService.PostStory(detail); return RedirectToAction("Index"); }
public ActionResult EditStory(StoryViewModel model, int[] selectedItems) { StoryDetail detail = model.ConvertToStoryDetail(); int[] items = selectedItems; if(selectedItems==null) { items = new int[0]; } if (model.Title == null)//Invalid Model State, dirty approach { model.AllGroups= new GroupViewModel[0]; TaskResult<IEnumerable<GroupDetail>> groupDetailRequest = groupDataService.GetGroups(new DataRequest { StartPosition = 0, Count = 100 }); if (groupDetailRequest.Data != null) { model.AllGroups = groupDetailRequest.Data.Select(a => a.ConvertToGroupViewModel()); } return View(model); } detail.GroupDetails = items.Select(a => new GroupDetail { Id = a }); storyDataService.PostStory(detail); return RedirectToAction("Index"); }
// GET: Story public ActionResult Index() { var storyRequest = storyDataService.GetStoriesByUser(UserDetails.Id.Value, new DataRequest { StartPosition=0,Count=50}); IEnumerable<StoryViewModel> model= new StoryViewModel[0]; if(storyRequest.Data!=null) { model = storyRequest.Data.Select(a => a.ConvertToStoryViewModel()).ToList(); } return View(model); }
public ActionResult ViewStory(StoryViewModel story) { return View(story); }