public static Drop MapToApiDrop(this Models.Drop value) { var tmp = new Drop { Id = value.Id, CreatorId = value.CreatorId, ValidTo = value.ValidTo, IsValidForever = !value.ValidTo.HasValue, Lon = value.Lon ?? 0, Lat = value.Lat ?? 0, Alt = value.Alt ?? 0, Date = value.Date ?? new DateTime(), Message = value.Message, Title = value.Title, }; return(tmp); }
public async Task <IActionResult> Post([FromBody] Drop value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!value.Validate()) { return(BadRequest()); } var drop = new Models.Drop() { CreatorId = value.CreatorId, ValidTo = value.ValidTo, IsValidForever = !value.ValidTo.HasValue, Lon = value.Lon ?? 0, Lat = value.Lat ?? 0, Alt = value.Alt ?? 0, Date = value.Date ?? new DateTime(), Message = value.Message, Title = value.Title, }; try { //add record to db set _dbContext.Drops.Add(drop); await _dbContext.SaveChangesAsync(); //update Id value.Id = drop.Id; //first notify clients about new position await Task.Run(() => Clients.All.NotifyNewDrop(value)).ConfigureAwait(false); } catch (Exception ex) { Debug.WriteLine(ex); throw; } return(CreatedAtRoute(routeName: GetDropByIdRoute, routeValues: new { value.Id }, value: value)); }