public Message(MessageODataHack hack) { Id = hack.Id; ShortName = hack.ShortName; Tooltip = hack.Tooltip; Type = hack.Type; HasBeenRead = hack.HasBeenRead; Author = hack.Author; Date = hack.Date; }
public async Task <IActionResult> Patch([FromBody] MessageODataHack payload, int key) { if (payload == null || key == 0) { return(BadRequest("Please put valid object in request body.")); } var obj = await _context.Messages.AsQueryable().SingleAsync(c => c.Id == key); if (obj == null) { return(BadRequest("Object with this Id was not found.")); } obj.HasBeenRead = payload.HasBeenRead; await _context.SaveChangesAsync(); return(Updated(obj)); }
public async Task <IActionResult> Post([FromBody] MessageODataHack payload) { if (payload == null) { return(BadRequest("Please put a valid object in request body.")); } var fixedPayload = new Message(payload) // hack, please check MessageODataHack summary. { Id = 0, HasBeenRead = false, Date = DateTime.Now }; await _context.Messages.AddAsync(fixedPayload); await _context.SaveChangesAsync(); return(Created(fixedPayload)); }