public async Task <ActionResult <UserReadDto> > GetUserById(int id) { Response.Headers.Add("Access-Control-Allow-Origin", "*"); var user = await _repository.GetUserById(id); if (user == null) { return(NotFound()); } return(Ok(_mapper.Map <UserReadDto>(user))); }
//[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Roles = "Admin")] public ActionResult <UserReadDto> GetUserById(string id) { var user = _repository.GetUserById(id); if (user != null) { return(Ok(_mapper.Map <UserReadDto>(user))); } else { return(NotFound()); } }
public ActionResult <StorageReadDto> CreateStorage(StorageCreateDto storageCreateDto) { var model = new Storage() { IdUser = _repository.GetUserById(storageCreateDto.UserId), StorageName = storageCreateDto.StorageName, }; _repository.CreateStorage(model); _repository.SaveChanges(); var readDto = _mapper.Map <StorageReadDto>(model); return(CreatedAtRoute(nameof(GetStorageById), new { Id = readDto.StorageId }, readDto)); }
public async Task <ActionResult> CreateMembership(MembershipCreateDto membershipCreateDto) { var user = await _repository.GetUserById(membershipCreateDto.UserId); var facility = await _repository.GetFacilityById(membershipCreateDto.FacilityId); var contract = await _repository.GetContractById(membershipCreateDto.ContractId); if (user == null) { ModelState.AddModelError(string.Empty, "User does not exist"); } if (facility == null) { ModelState.AddModelError(string.Empty, "Facility ID does not exist"); } if (contract == null) { ModelState.AddModelError(string.Empty, "Contract ID does not exist"); } if (ModelState.ErrorCount > 0) { return(ValidationProblem(ModelState)); } bool success = await _repository.CreateMembership(_mapper.Map <Membership>(membershipCreateDto)); if (success) { return(NoContent()); } return(Conflict()); }
public ActionResult <ExpireReadDto> CreateExpire(ExpireCreateDto expireCreateDto) { var model = new Expire() { ExpirationDate = expireCreateDto.ExpirationDate.Date, IdUser = _repository.GetUserById(expireCreateDto.UserId), IdItem = _repository.GetItemById(expireCreateDto.IdItem), IdStorage = _repository.GetStorageById(expireCreateDto.IdStorage), }; _repository.CreateExpire(model); _repository.SaveChanges(); var readDto = _mapper.Map <ExpireReadDto>(model); return(CreatedAtRoute(nameof(GetExpireById), new { Id = readDto.ExpireId }, readDto)); }