Exemplo n.º 1
0
        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);
        }