Example #1
0
        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));
            }
        }
Example #2
0
        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 }));
     }
 }
Example #4
0
 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));
     }
 }
Example #5
0
        public RESTSingleResponse <IncidentPostResponse> Post([FromBody] IncidentPostParam @params)
        {
            var result = _incidentService.Create(@params);

            return(result);
        }