Example #1
0
        public void Update(IncidentUpdateRequest incidentUpdateRequest)
        {
            var upvotes   = SqlInt32.Null;
            var downvotes = SqlInt32.Null;

            if (incidentUpdateRequest.Upvotes > 0)
            {
                upvotes = incidentUpdateRequest.Upvotes;
            }
            if (incidentUpdateRequest.Downvotes > 0)
            {
                downvotes = incidentUpdateRequest.Downvotes;
            }

            _dataProvider.ExecuteNonQuery(
                "incidents_update",
                inputParamMapper : delegate(SqlParameterCollection paramCol)
            {
                paramCol.AddWithValue("@Id", incidentUpdateRequest.Id);
                paramCol.AddWithValue("@OffenseType", incidentUpdateRequest.OffenseType);
                paramCol.AddWithValue("@Incident", incidentUpdateRequest.Incident);
                paramCol.AddWithValue("@IncidentDate", incidentUpdateRequest.IncidentDate);
                paramCol.AddWithValue("@IncidentTime", incidentUpdateRequest.IncidentTime);
                paramCol.AddWithValue("@Location", incidentUpdateRequest.Location);
                paramCol.AddWithValue("@Upvotes", upvotes);
                paramCol.AddWithValue("@Downvotes", downvotes);
                paramCol.AddWithValue("@AdditionalDescription", string.IsNullOrEmpty(incidentUpdateRequest.AdditionalDescription) ? null : incidentUpdateRequest.AdditionalDescription);
            }
                );
        }
        public async Task <HttpResponseMessage> UpdateIncident(IncidentUpdateRequest request)
        {
            client.DefaultRequestHeaders.Add("Access-Control-Allow-Origin", "*");
            client.DefaultRequestHeaders.Add("Access-Control-Allow-Credentials", "true");
            client.DefaultRequestHeaders.Add("Access-Control-Allow-Headers", "Access-Control-Allow-Origin,Content-Type");
            var serialized    = System.Text.Json.JsonSerializer.Serialize(request);
            var stringContent = new StringContent(serialized, Encoding.UTF8, "application/json");
            var result        = await client.PostAsync($"/Incident/update", stringContent);

            return(result);
        }
        public async Task HandleValidSubmit()
        {
            HttpResponseMessage result = null;

            if (Model.IncidentId == null || Model.IncidentId.Value == 0)
            {
                var request = new IncidentCreateRequest();
                request.Incident.Created      = Model.Created;
                request.Incident.Modified     = DateTime.UtcNow;
                request.Incident.Dog          = DogModel;
                request.Incident.Title        = Model.Title;
                request.Incident.Description  = Model.Description;
                request.Incident.IncidentDate = Model.IncidentDate;
                request.Incident.IncidentType = Model.IncidentType;
                result = await Client.CreateIncident(request);
            }
            else
            {
                var request = new IncidentUpdateRequest();
                request.Incident.IncidentId   = Model.IncidentId;
                request.Incident.Deleted      = Model.Deleted;
                request.Incident.Created      = Model.Created;
                request.Incident.Modified     = Model.Modified;
                request.Incident.Dog          = DogModel;
                request.Incident.Title        = Model.Title;
                request.Incident.Description  = Model.Description;
                request.Incident.IncidentDate = Model.IncidentDate;
                request.Incident.IncidentType = Model.IncidentType;
                result = await Client.UpdateIncident(request);
            }
            if (result.IsSuccessStatusCode)
            {
                NotificationService.Notify(NotificationSeverity.Success, "Saved successfully");
                ShowEditData   = false;
                IncidentModels = await Client.GetAllIncident();

                IncidentModels = IncidentModels.OrderByDescending(x => x.IncidentDate).ToList();
                StateHasChanged();
            }
            else
            {
                NotificationService.Notify(NotificationSeverity.Error, "Failed", result.ReasonPhrase, 6000);
            }
        }
Example #4
0
 public HttpResponseMessage Update(IncidentUpdateRequest model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var resp = new SuccessResponse();
             _incidentService.Update(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 bool Update([FromBody] IncidentUpdateRequest request)
 {
     return(_incidentManager.UpdateIncident(request));
 }
Example #6
0
 public bool UpdateIncident(IncidentUpdateRequest request)
 {
     return(_incidentRepository.UpdateIncident(request.Incident));
 }