Exemple #1
0
        public virtual async Task <IActionResult> UpdateAsync(int peoplesId, [FromBody] PeoplesV1Simple item, CancellationToken cancellationToken = default(CancellationToken))
        {
            using (Logger.Perfs())
            {
                try
                {
                    if (item == null || !ModelState.IsValid)
                    {
                        return(BadRequest(Helper.FormatModelStateError(ModelState)));
                    }
                    if (!CheckIds(peoplesId, item))
                    {
                        throw new PayloadPKAndRoutingException("Payload key and routing are different");
                    }
                    await APIService.UpdateAsync(item, cancellationToken);

                    return(Ok(Helper.FormatDefaultResponse(true, "Update done", $"Resource PeoplesV1 updated.")));
                }
                catch (APIObjNotFoundException e)
                {
                    return(NotFound(Helper.FormatExceptionError(e)));
                }
                catch (Exception e)
                {
                    return(BadRequest(Helper.FormatExceptionError(e)));
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Checking that id from item and given ids are the same
 /// </summary>
 /// <param name="peoplesId"><see cref="int"/></param>
 /// <param name="item">Item to check</param>
 /// <returns>bool</returns>
 private bool CheckIds(int peoplesId, PeoplesV1Simple item)
 {
     return(peoplesId == item.Id);
 }