public IHttpActionResult PostDriver([FromUri] string senderID, [FromBody] DriverModel driverModel) { Driver driver = new Driver(driverModel.Username, driverModel.Password) { FirstName = driverModel.FirstName, LastName = driverModel.LastName, Gender = driverModel.Gender, JMBG = driverModel.JMBG, Phone = driverModel.Phone, Email = driverModel.Email, DriversLocation = DbLocation.GetSingleEntityByKey(driverModel.DriversLocationID), DriversVehicle = DbVehicle.GetSingleEntityByKey(driverModel.DriversVehicleID), }; driverModel.TaxiDrivesIDs.ForEach(td => driver.TaxiDrives.Add(DbTaxiDrive.GetSingleEntityByKey(td))); if (!LoggedUsers.Contains(senderID)) { return(Content(HttpStatusCode.Unauthorized, "Not logged in.")); } else if (!DbAdmin.Exists(senderID)) { return(Content(HttpStatusCode.Unauthorized, "Not a dispatcher.")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } bool result; try { result = DbDriver.Add(driver); } catch (Exception e) { Trace.Write($"Error on 'PostDriver()'. Error message: {e.Message}"); Trace.Write($"[STACK_TRACE] {e.StackTrace}"); return(InternalServerError(e)); } if (result) { return(Ok(driver)); } else { return(BadRequest("Driver already exists.")); } }