Exemple #1
0
        public IActionResult PutDamage(int id, [FromBody] DamageViewModel vmdl)
        {
            if (id != vmdl.DamageId)
            {
                return(BadRequest());
            }

            try
            {
                var damage = _bl.GetDamage(vmdl.DamageId);
                _bl.UpdateDamage(damage);
                vmdl.Update(damage, _bl);
                _bl.SaveChanges();

                _log.LogInformation("Damage '{0}({1})' updated by '{2}'", vmdl.DamageId, vmdl.DamageStatus, User.Identity.Name);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_bl.DamageExists(id))
                {
                    _log.LogWarning("Not Found: Damage '{0}' not found", id);
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            catch (SecurityException)
            {
                _log.LogError("Security: '{0}' tried to update Device '{1}'", vmdl.DamageId);
            }
            catch (Exception ex)
            {
                _log.LogError("Exception: {0}", ex);
                return(StatusCode(500));
            }



            return(Ok(vmdl));
        }