public IHttpActionResult Put(int id, [FromBody] MapObjectViewModel mapObject) { try { if (id == mapObject.Id) { // This is for confirmation by the administrator. // From the confirmation page comes the mapObject with the fields Id and Status. // We find the object in the database, load it, change its status and save it. if (mapObject.Status == Status.Approved) { mapObject.TimeStamp = DateTime.Now; mapObject = Mapper .Map <MapObjectDTO, MapObjectViewModel>(mapObjectService.GetMapObject(id)); mapObject.Status = Status.Approved; } var approvedMapObject = Mapper .Map <MapObjectViewModel, MapObjectDTO>(mapObject); mapObjectService.UpdateMapObject(approvedMapObject); return(Ok()); } return(BadRequest()); } catch { return(BadRequest()); } }
/// <summary> /// Method for updating the object in the database. /// </summary> /// <param name="id">Object's ID.</param> /// <param name="mapObject">Updating object.</param> /// <returns> If the update is successful, it returns OkResult(). /// If an exception occurs, then BadRequest.</returns> public IHttpActionResult Put(int id, [FromBody] MapObjectViewModel mapObject) { try { if (id == mapObject.Id) { mapObject.TimeStamp = DateTime.Now; var updateMapObject = Mapper .Map <MapObjectViewModel, MapObjectDTO>(mapObject); mapObjectService.UpdateMapObject(updateMapObject); return(Ok()); } return(BadRequest()); } catch { return(BadRequest()); } }