public IActionResult Put(int id, [FromBody] Warningtime value) { try { var owner = User.Identity.Name; if (owner == null) { return(StatusCode(StatusCodes.Status401Unauthorized)); } var warningtime = this.dbContext.Warningtime.FirstOrDefault(p => p.ID == id && p.Owner == owner); if (warningtime == null) { return(StatusCode(StatusCodes.Status404NotFound)); } warningtime.dayhour = value.dayhour; this.dbContext.Warningtime.Update(warningtime); this.dbContext.SaveChanges(); return(StatusCode(StatusCodes.Status202Accepted)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public IActionResult Post([FromBody] Warningtime value) { //This line added from tutorial if (value == null) { return(BadRequest()); } var owner = User.Identity.Name; if (owner == null) { return(StatusCode(StatusCodes.Status401Unauthorized)); } value.Owner = owner; this.dbContext.Add(value); this.dbContext.SaveChanges(); return(StatusCode(201)); }