예제 #1
0
        public async Task <Specialty> Handle(CreateSpecialtyCommand request, CancellationToken cancellationToken)
        {
            var uuid   = Guid.NewGuid();
            var entity = new Specialty
            {
                Uuid = uuid,
                Name = request.Name
            };

            await _dbContext.AddAsync(entity, cancellationToken);

            await _dbContext.SaveChangesAsync(cancellationToken);

            return(entity);
        }
예제 #2
0
        public async Task <IActionResult> UpdateSpecialty(int id, SpecialtyDto specialty)
        {
            if (id != specialty.Id)
            {
                return(BadRequest());
            }

            var specialtyUpdated = await _context.Specialties.FindAsync(id);

            if (specialtyUpdated == null)
            {
                return(NotFound());
            }

            specialtyUpdated.Name = specialty.Name;

            _context.Entry(specialtyUpdated).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SpecialtyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #3
0
        public async Task <IActionResult> UpdateVet(int id, VetDto vet)
        {
            if (id != vet.Id)
            {
                return(BadRequest());
            }

            var vetUpdated = await _context.Vets.FindAsync(id);

            if (vetUpdated == null)
            {
                return(NotFound());
            }

            _mapper.Map(vet, vetUpdated);

            _context.Entry(vet).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VetExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #4
0
        public async Task <IActionResult> UpdateOwner(int id, OwnerDto owner)
        {
            if (id != owner.Id)
            {
                return(BadRequest());
            }

            var ownerUpdated = await _context.Owners.FindAsync(id);

            if (ownerUpdated == null)
            {
                return(NotFound());
            }

            _mapper.Map(owner, ownerUpdated);

            _context.Entry(ownerUpdated).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OwnerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }