public async Task <IActionResult> Create([FromForm] IncidentModel model) //[FromForm] - potrzebne do mapowania danych z formularza na obiekt w przypadku gdy korzystamy z Razora lub zwykłego HTMLa. Przy taghelperach nie jest to konieczne tak jak w tym przypadku { if (ModelState.IsValid) { try { //var user = await signInManager.UserManager.FindByIdAsync(User.Identity.ToString()); //model.CreatedBy = model.ModifiedBy = user; //model.UserId = User.Identity.Name; // model.ListPriorites = new SelectList(_modelService.GetAll()); _modelService.Create(model); //context.SaveChanges(); } catch (Exception) { return(View(model)); } return(Redirect("Index")); } else { return(View(model)); } }
public async Task <IActionResult> Create([FromBody] CreateIncidentModel model) { return(await ProcessAsync(async() => { var user = await UserService.GetUserByPrincipal(User); var incident = new IncidentModel { AcademicYearId = model.AcademicYearId, StudentId = model.StudentId, BehaviourTypeId = model.BehaviourTypeId, Comments = model.Comments, CreatedDate = DateTime.Now, LocationId = model.LocationId, OutcomeId = model.OutcomeId, Points = model.Points, StatusId = model.StatusId, RecordedById = user.Id }; await _incidentService.Create(incident); return Ok("Incident created."); }, Permissions.Behaviour.Incidents.EditIncidents)); }
public IActionResult CreateIncident(Incident incident, int userId) { try { _incidentService.Create(incident, userId); return(Ok()); } catch (Exception e) { return(BadRequest(new { message = e.Message })); } }
public HttpResponseMessage Create(IncidentAddRequest model) { try { if (ModelState.IsValid) { var resp = new ItemResponse <int> { Item = _incidentService.Create(model) }; return(Request.CreateResponse(HttpStatusCode.OK, resp)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState)); } } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ex)); } }
public RESTSingleResponse <IncidentPostResponse> Post([FromBody] IncidentPostParam @params) { var result = _incidentService.Create(@params); return(result); }