public async Task <ResponseLogic> CreateAsync(UserCreateDTO user, string azureUId) { var existing = await _repository.FindFromAzureUIdAsync(azureUId); if (existing != null) { return(ResponseLogic.ALREADY_EXISTS); } if (user.Location != null) { var success = await _locationLogic.CreateAsync(new LocationCreateDTO() { City = user.Location.City, Country = user.Location.Country }); if (success == ResponseLogic.SUCCESS) { user.Location = await _locationLogic.FindExactAsync(user.Location.City, user.Location.Country); } else { return(ResponseLogic.ERROR_CREATING); } } var id = await _repository.CreateAsync(user, azureUId); if (id == 0) { return(ResponseLogic.ERROR_CREATING); } return(ResponseLogic.SUCCESS); }
public async Task <(ResponseLogic outcome, int Id)> CreateAsync(CreateProjectDTO project, int creatorId) { if (project.Location != null) { var success = await _locationLogic.CreateAsync(new LocationCreateDTO() { City = project.Location.City, Country = project.Location.Country }); if (success == ResponseLogic.SUCCESS) { project.Location = await _locationLogic.FindExactAsync(project.Location.City, project.Location.Country); } else { return(ResponseLogic.ERROR_CREATING, 0); } } if (project.Category != null) { var success = await _categoryLogic.CreateAsync(new CategoryCreateDTO() { Name = project.Category.Name }); if (success == ResponseLogic.SUCCESS) { project.Category = await _categoryLogic.FindExactAsync(project.Category.Name); } else { return(ResponseLogic.ERROR_CREATING, 0); } } var id = await _repository.CreateAsync(project, creatorId); if (id == 0) { return(ResponseLogic.ERROR_CREATING, 0); } return(ResponseLogic.SUCCESS, id); }
public async Task <IActionResult> Post([FromBody] LocationCreateDTO location) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var success = await _locationLogic.CreateAsync(location); if (success == ResponseLogic.SUCCESS) { var createdLocation = await _locationLogic.FindExactAsync(location.City, location.Country); return(CreatedAtAction(nameof(Get), new { createdLocation.Id }, createdLocation.Id)); } else { return(StatusCode(500)); } }