Beispiel #1
0
        public ComputerLabForList UpdateComputerLab(int id, ComputerLabForInsert computerLab)
        {
            var labToUpdate = GetById(id);

            _mapper.Map(computerLab, labToUpdate);
            _context.SaveChanges();

            return(_mapper.Map <ComputerLabForList>(GetById(id)));
        }
Beispiel #2
0
        public ComputerLabForList AddComputerLab(ComputerLabForInsert computerLab)
        {
            if (_context.ComputerLabs.Any(l => string.Equals(l.Name, computerLab.Name)))
            {
                throw new BadRequestException("Phòng máy này đã tồn tại");
            }

            var labToAdd = _mapper.Map <ComputerLab>(computerLab);

            labToAdd.Owner = _context.Users.Find(computerLab.OwnerId);

            Add(labToAdd);

            return(_mapper.Map <ComputerLabForList>(labToAdd));
        }
        public ComputerLabForList UpdateComputerLab(int id, ComputerLabForInsert computerLab)
        {
            var ownerId  = Convert.ToInt32(User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var labOwner = _service.GetById(id).OwnerId;

            if (ownerId != 8 && labOwner != ownerId)
            {
                throw new ForbiddenException("Không có quyền chỉnh sửa phòng máy này");
            }

            computerLab.OwnerId = labOwner;

            var updatedLab = _service.UpdateComputerLab(id, computerLab);

            return(updatedLab);
        }
        public ComputerLabForList AddComputerLab(ComputerLabForInsert computerLab)
        {
            computerLab.OwnerId = Convert.ToInt32(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            return(_service.AddComputerLab(computerLab));
        }