public async Task <IActionResult> CreateItem(int userid, ItemForCreateDto itemForCreateDto) { if (userid != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var userFromRepo = await _repo.GetUser(userid); //userem itemForCreateDto.LastModifier = userFromRepo; itemForCreateDto.Name = itemForCreateDto.Name.ToLower(); if (await _repo.ItemExists(itemForCreateDto.Name)) { return(BadRequest("Item already exists")); } var itemToCreate = _mapper.Map <Item>(itemForCreateDto); _repo.Add(itemToCreate); if (await _repo.SaveAll()) { return(StatusCode(201)); } throw new Exception("Nem sikerült a hozzáadás"); }
public async Task <IActionResult> AddUser(UserForAddDto userForAddDto) { userForAddDto.UserName = userForAddDto.UserName.ToLower(); // létezik e már if (await _repo.UserExists(userForAddDto.UserName)) { return(BadRequest("Username already exists")); } var userToCreate = _mapper.Map <User>(userForAddDto); //mapper kell _repo.Add(userToCreate); return(StatusCode(201)); // var userToReturn = _mapper.Map<UserForDetailedDto>(createdUser); // return CreatedAtRoute("GetUser", new {controller = "Users", id = createdUser.Id}, userToReturn); }
public async Task <ValueWrapper <bool> > Handle(UploadBlobCommand request, CancellationToken cancellationToken) { await _repository.Add(request.Filename, request.Bytes, cancellationToken); return(new ValueWrapper <bool>(true)); }