public async Task <BaseResponse <ComputerDto> > GetComputer(Guid id) { if (!(await _computerRepository.Exists(id))) { return(BaseResponse <ComputerDto> .NotFound("Computer id not found")); } var result = await _computerRepository.Get(id); return(new BaseResponse <ComputerDto>((int)HttpStatusCode.OK, _mapper.Map <ComputerDto>(result))); }
public ComputerModelDTO GetComputer(int id) { ComputerModelDTO computer = _mapper.Map <ComputerModelDTO>(_computerRepository.Get(id)); computer.States = _mapper.Map <IEnumerable <StateModelDTO> >(_stateRepository.GetAll()).ToList(); LoanModelDTO loan = _mapper.Map <IEnumerable <LoanModelDTO> >(_loanRepository.GetAll()).Where(l => l.ComputerId == computer.Id).OrderByDescending(l => l.LoanDate).FirstOrDefault(); if (loan != null) { computer.LendBy = _userRepository.GetUsernameById(loan.UserId); if (loan.LoanDate != null) { computer.LoanDate = loan.LoanDate; } if (loan.ReturnedDate != null) { computer.ReturnedDate = loan.ReturnedDate; } } return(computer); }
public Response <Persistence.Models.Computer[]> List() { var cache = new InMemoryRepositoryModelCache(); var computers = _computerRepository.Get(_user, cache); var result = computers.Select(GetSerializableVersion) .ToArray(); return(Response.Create(result)); }
public Computer Get(int id) { var computerRepo = _repository.Get(id); return(new Computer { Id = computerRepo.Id, Description = computerRepo.Description, Date = computerRepo.Date, MaintenanceDate = computerRepo.MaintenanceDate }); }
public static CleaningResult Clean(this IScriptRepository repository, ITaskRepository taskRepository, IComputerRepository computerRepository, ListFilter filter = null, IRepositoryModelCache cache = null) { if (filter == null) { filter = new ListFilter { SortDirection = SortDirection.Ascending }; } var allScripts = repository.List(filter).Items; var unusedScripts = allScripts.Where(x => { var getOwnersFunctions = new Func <Script, object[]>[] { (id) => taskRepository.Get(id, cache), (id) => computerRepository.Get(id, cache) }; foreach (var getOwnersFunction in getOwnersFunctions) { var owners = getOwnersFunction(x); if (owners.Any()) { return(false); } } return(true); }).ToArray(); foreach (var script in unusedScripts) { repository.Remove(script); } var result = new CleaningResult(filter, allScripts.Length, unusedScripts.Length); return(result); }
public static Computer ToRepositoryType(IRepositoryModelCache cache, int?id, IComputerRepository computerRepository) { if (id == null) { return(null); } var cachedValue = cache?.Get <Computer>(id); if (cachedValue != null) { return(cachedValue); } if (computerRepository == null) { return(new ComputerModel { Id = id.Value }.ToRepositoryType(cache, (IScriptRepository)null, (IUserRepository)null)); } return(computerRepository.Get(id.Value, cache)); }