Ejemplo n.º 1
0
        public async Task <Project> AddProjectAsync(UpsertProjectParams ps)
        {
            if (await _context.Projects.AsNoTracking().AnyAsync(p => p.ProjectKey == ps.ProjectKey))
            {
                throw new ConflictException($"Project with key {ps.ProjectKey} is already existing.");
            }

            var project = _mapper.Map <Project>(ps);

            await _context.Projects.AddAsync(project);

            await _context.SaveChangesAsync();

            return(project);
        }
Ejemplo n.º 2
0
        public async Task <Project> UpdateProjectAsync(UpsertProjectParams ps)
        {
            var oldProject = await _context.Projects.FirstOrDefaultAsync(p => p.ProjectKey == ps.ProjectKey);

            if (oldProject == null)
            {
                throw new NotFoundException($"The project {ps.ProjectKey} cannot be found.");
            }

            _mapper.Map(ps, oldProject);

            await _context.SaveChangesAsync();

            return(oldProject);
        }