// PUT api/<controller>/5 public void Put(long id, [FromBody] EditRouteInfo model) { var route = DB.Routes.FirstOrDefault(x => !x.IsSoftDeleted && x.Id == id); if (route != null) { // Route Completed ? switch (Helpers.RouteHelpers.Categorize(route.DepartureTime, route.ArrivalTime)) { case BusRouteState.Used: case BusRouteState.Active: if (model.DepartureTime != null || model.ArrivalTime != null || model.From != null || model.Destination != null || model.FromLat != null || model.FromLng != null || model.DestinationLat != null || model.DestinationLng != null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Cannot modify the route in its current state!")); } break; } ObjectMapper.CopyPropertiesTo(model, route, ObjectMapper.UpdateFlag.DeferUpdateOnNull); DB.SaveChanges(); } }
// PUT api/<controller>/5 public void Put(int id, [FromBody] EditBusInfo value) { var bus = DB.Buses.FirstOrDefault(x => x.Id == id); if (bus == null) { ObjectMapper.CopyPropertiesTo(value, bus, ObjectMapper.UpdateFlag.DeferUpdateOnNull | ObjectMapper.UpdateFlag.DenoteEmptyStringsAsNull); DB.SaveChanges(); } }
public IHttpActionResult UpdateProfile([FromBody] UpdateUserInfo model) { var user = DB.Users.Find(UserId); if (user == null) { return(NotFound()); } ObjectMapper.CopyPropertiesTo(model, user, ObjectMapper.UpdateFlag.DeferUpdateOnNull, new string[] { nameof(user.Username), nameof(user.FullName) }); DB.SaveChanges(); return(Empty()); }