public async Task <IActionResult> Post([FromBody] SurveyVm viewModel) { return(await ExecuteAsync(async() => { var result = await _surveyService.AddSurvey(viewModel); return result; })); }
public HttpResponseMessage Post([FromBody] SurveyDto survey) { try { _service.AddSurvey(survey); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }
public IActionResult Create(Survey survey) { if (ModelState.IsValid) { var username = User.FindFirstValue(ClaimTypes.Name); User user = userService.GetUserByUsername(username); surveyService.AddSurvey(survey, user); userSurveyService.AddUserSurvey(user, survey); return(RedirectToAction(nameof(Index))); } return(View()); }
// GET: Survey public ActionResult Index() { var insertItem = new Survey(); insertItem.SurveyDepartman = SharedKernel.Enums.Departman.RD; insertItem.SurveyName = "Deneme"; insertItem.Id = Guid.NewGuid(); insertItem.SurveyStartingDate = DateTime.UtcNow; insertItem.SurveyEndingDate = DateTime.UtcNow; insertItem.Status = SharedKernel.Enums.Status.Active; _surveyService.AddSurvey(insertItem); var model = _surveyService.GetActiveSurveyList(); return(View(model)); }
public async Task <IActionResult> CreateSurvey([FromBody] SurveyModel survey) { if (!ModelState.IsValid) { return(BadRequest("Niepoprawne dane")); } var result = await surveyService.AddSurvey(survey); if (result.StateMessage == CommonResultState.OK) { return(Ok(result.Message)); } return(BadRequest(result.Message)); }
public async Task <IActionResult> AddANewSurvey(HomeViewModel homeViewModel, [FromServices] ISurveyService surveyService) { if (ModelState.IsValid) { var survey = new Survey { Title = homeViewModel.SurveyTitle, Description = homeViewModel.SurveyDescription }; await surveyService.AddSurvey(survey); return(RedirectToAction("Index", "CreateSurvey", new { id = survey.Id })); } else { return(View("Index", homeViewModel)); } }
public async Task <IActionResult> Add([FromBody] SurveyDto dto) { _logger.LogInformation("Performing insert request..."); if (Util.IsAnyNullOrEmpty(dto)) { _logger.LogWarning("Body from request is empty."); return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } _logger.LogInformation("Saving record..."); await _surveyService.AddSurvey(dto); _logger.LogInformation("Record saved successfully. Redirecting to record info..."); return(RedirectToAction(nameof(GetSurveyById), new { id = dto.Id })); }
public ActionResult AddSurvey(Survey survey) { if (HttpContext.Session.GetString("Role") == "Teacher") { survey.CreateFor = "Student"; } if (survey.Title == null && survey.CreateFor == null) { ViewBag.errorTitle = "Set a title!"; ViewBag.errorCreateFor = "set a role to complete this survey!"; return(View("Views/CreateSurvey/Index.cshtml")); } else if (survey.Title == null) { ViewBag.errorTitle = "Set a title!"; return(View("Views/CreateSurvey/Index.cshtml")); } else if (survey.CreateFor == null) { ViewBag.errorCreateFor = "Set a role to complete this survey!"; return(View("Views/CreateSurvey/Index.cshtml")); } Survey survey2 = new Survey(); survey2.Title = survey.Title; survey2.CreateFor = survey.CreateFor; survey2.User = userService.GetUserById((int)HttpContext.Session.GetInt32("Id")); int surveyid = surveyService.AddSurvey(survey2); Survey survey3 = surveyService.GetSurvey(surveyid); DataModel model = new DataModel(); model.Survey = survey3; ViewBag.question = 1; return(View("Views/Question/Index.cshtml", model)); }