public IHttpActionResult Create(CreateLocationDataModel newLocation) { string userName = this.User.Identity.GetUserName(); CreateLocationDataModel addedLocation = this.locationsService.CreateLocation(newLocation, userName); return(Ok(addedLocation)); }
public Task <LocationDTO> CreateLocationAsync(CreateLocationDataModel createLocationDataModel, CancellationTokenSource cancellationTokenSource) => Task <LocationDTO> .Run(async() => { if (!CrossConnectivity.Current.IsConnected) { throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION); } LocationDTO createdLocation = null; CreateLocationRequest createLocationRequest = new CreateLocationRequest() { AccessToken = GlobalSettings.Instance.UserProfile.AccesToken, Data = createLocationDataModel, Url = GlobalSettings.Instance.Endpoints.ScheduleEndpoints.CreateNewLocation }; try { CreateLocationResponse createLocationResponse = await _requestProvider.PostAsync <CreateLocationRequest, CreateLocationResponse>(createLocationRequest); if (createLocationResponse != null) { createdLocation = BuildLocation(createLocationResponse); } else { throw new InvalidOperationException(CREATE_LOCATION_COMMON_ERROR_MESSAGE); } } catch (ServiceAuthenticationException exc) { _identityUtilService.RefreshToken(); throw exc; } catch (Exception exc) { Crashes.TrackError(exc); throw; } return(createdLocation); }, cancellationTokenSource.Token);
public CreateLocationDataModel CreateLocation(CreateLocationDataModel model, string userName) { Location newLocation = new Location { Author = userName, DateCreated = DateTime.Now, Name = model.Name, CountryId = model.CountryId, Description = model.Description, PhotoUrl = model.PhotoUrl, UsersWhoLikedThis = new HashSet <User>() }; this.data.Locations.Add(newLocation); this.data.SaveChanges(); model.Id = newLocation.Id; model.DateCreated = newLocation.DateCreated; return(model); }