public IActionResult Create(UniversalPoll poll) { //var username = "******"; var username = cache.GetString(username_key); if (string.IsNullOrEmpty(username)) { TempData["message"] = "Please login."; return(RedirectToAction(nameof(Index))); } try { poll.Id = Guid.NewGuid().ToString(); poll.Choices = poll.Choices.Where(c => !string.IsNullOrWhiteSpace(c.Title)).ToList(); foreach (var choice in poll.Choices) { choice.Id = Guid.NewGuid().ToString(); choice.Voters = Enumerable.Empty <Voter>(); } poll.CreateDate = DateTime.UtcNow; poll.Owner = username; pollBiz.Create(poll); TempData["message"] = "Add success"; } catch (Exception ex) { TempData["message"] = ex.Message; return(View()); } return(RedirectToAction(nameof(List))); }
public void Create(UniversalPoll poll) { if (string.IsNullOrWhiteSpace(poll.Title)) { throw new Exception("ไม่มีชื่อเรื่อง"); } if (poll.Choices == null || !poll.Choices.Any()) { throw new Exception("ไม่มีตัวเลือก"); } pollDac.Create(poll); }
public void CreateFailNoTitle(UniversalPoll poll, string expectedMessage) { var message = string.Empty; try { pollBiz.Create(poll); } catch (Exception ex) { message = ex.Message; } message.Should().Be(expectedMessage); pollDac.Verify(dac => dac.Create(It.IsAny <UniversalPoll>()), Times.Never); }
public void CreateComplete(UniversalPoll poll) { pollBiz.Create(poll); pollDac.Verify(dac => dac.Create(It.IsAny <UniversalPoll>()), Times.Once); }