Esempio n. 1
0
        public async Task<ViewResult> Submit(string feedName)
        {
            ViewBag.Tags = new string[0];

            if (feedName != null)
            {
                ViewBag.Tags = await WebApiService.Instance.GetAsync<IEnumerable<string>>("/FeedEntries/Tags", UserManager.User.AccessToken, new { feedName });
            }

            var feedEntryViewModel = new CreateFeedEntryViewModel
            {
                FeedName = feedName
            };
            return View(feedEntryViewModel);
        }
Esempio n. 2
0
        public async Task<ActionResult> Submit(CreateFeedEntryViewModel feedEntryViewModel, FeedEntryType submitType)
        {
            Log.Info("Received new feedentry:" + feedEntryViewModel.Title);
            if (ModelState.IsValid)
            {
                //create
                var feedEntry = Mapper.Map<CreateFeedEntryDto>(feedEntryViewModel);
                if (submitType == FeedEntryType.Attachment)
                {
                    feedEntry.FeedEntryType = WebApi.Public.FeedEntryType.Attachment;
                    if (feedEntryViewModel.Attachment == null)
                    {
                        ModelState.AddModelError("Attachment", "Invalid attachment");
                        return View(feedEntryViewModel);
                    }

                    var createdEntryViewModel = await WebApiService.Instance.PostAsync<FeedEntryDto>("/FeedEntries/Create", UserManager.User.AccessToken, feedEntry);

                    await WebApiService.Instance.PostFileAsync<FeedEntryDto>("/Documents/Upload", UserManager.User.AccessToken, new { feedName = feedEntryViewModel.FeedName, guid = createdEntryViewModel.DocumentId },
                         feedEntryViewModel.Attachment);

                    await WebApiService.Instance.PostAsync<FeedEntryDto>("/FeedEntries/AttachDocument", UserManager.User.AccessToken, new { feedName = feedEntryViewModel.FeedName, guid = createdEntryViewModel.Guid, documentId = createdEntryViewModel.DocumentId });


                    return RedirectToAction("Show", createdEntryViewModel.GetRouteValues());
                }
                if (submitType == FeedEntryType.Link)
                {
                    feedEntry.FeedEntryType = WebApi.Public.FeedEntryType.Link;

                    if (string.IsNullOrEmpty(feedEntryViewModel.Link))
                    {
                        ModelState.AddModelError("Link", "Missing link");
                        return View(feedEntryViewModel);
                    }
                    var createdEntryViewModel = await WebApiService.Instance.PostAsync<FeedEntryDto>("/FeedEntries/Create", UserManager.User.AccessToken, feedEntry);
                    return RedirectToAction("Show", createdEntryViewModel.GetRouteValues());
                }
                ModelState.AddModelError("submitType", "Invalid submit type!");
                return View(feedEntryViewModel);
            }
            string messages = string.Join("; ", ModelState.Values
                .SelectMany(x => x.Errors)
                .Select(x => x.ErrorMessage));
            Log.Error("Invalid state: " + messages);


            var feedEntryDto = await WebApiService.Instance.GetAsync<IEnumerable<string>>("/FeedEntries/Tags", UserManager.User.AccessToken, new { feedEntryViewModel.FeedName });
            ViewBag.Tags = feedEntryDto;

            return View(feedEntryViewModel);
        }