예제 #1
0
        public async Task <UserDTO> Update(UserDTO userDTO)
        {
            var user     = _mapper.Map <User>(userDTO);
            var existing = await _context.Users
                           .Include(u => u.UserSocialNetworks)
                           .FirstOrDefaultAsync(x => x.Id == userDTO.Id);

            if (existing == null)
            {
                throw new NotFoundException("user", userDTO.Id);
            }
            _context.Entry(existing).CurrentValues.SetValues(user);
            await _context.SaveChangesAsync();

            return(_mapper.Map <UserDTO>(existing));
        }
        /// <summary />
        /// <exception cref="ArgumentException">Throws an exception when doesn't exist entity with id</exception>
        public virtual async Task UpdateAsync(TEntityDTO dto)
        {
            var entity = Mapper.Map <TEntity>(dto);

            if (!await ExistAsync(entity.Id))
            {
                throw new ArgumentException(entity.Id.ToString());
            }

            Context.Entry(entity).State = EntityState.Modified;
            await Context.SaveChangesAsync();
        }
예제 #3
0
        public async Task <ProjectRemoteTriggerDTO> UpdateProjectTrigger(ProjectRemoteTriggerDTO triggerDTO)
        {
            if (triggerDTO == null)
            {
                throw new NullDTOException(typeof(ProjectRemoteTriggerDTO));
            }

            var trigger = await _context.ProjectRemoteTriggers.FirstOrDefaultAsync(t => t.Id == triggerDTO.Id);

            if (trigger == null)
            {
                throw new NotFoundException("RemoteTrigger", triggerDTO.Id);
            }

            _mapper.Map(triggerDTO, trigger);

            _context.Entry(trigger).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(_mapper.Map <ProjectRemoteTriggerDTO>(trigger));
        }