public bool addCategorieProfilePicture(categoriePictureDto categoriePictureDto, string url) { User user = this._dataContext.users.FirstOrDefault(x => x.id == categoriePictureDto.userId); Categorie categorie = this._dataContext.categories.FirstOrDefault(x => x.id == categoriePictureDto.categorieId); if (user == null || categorie == null) { return(false); } categorie.imageUrl = url; return(this._dataContext.SaveChanges() > 0); }
public async Task <ActionResult <string> > addCategorieCoverPicture([FromForm] categoriePictureDto categoriePictureDto) { if (categoriePictureDto.userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized("You are not the User")); } Categorie categorie = await _db.getCategorie(categoriePictureDto.categorieId); if (categorie == null) { return(BadRequest("Categorie doesn't exist")); } User user = await _db.getUser(categoriePictureDto.userId); if (categorie == null) { return(BadRequest("Categorie doesn't exist")); } if (user == null) { return(BadRequest("this user doesn't exist")); } if (categorie.userId != user.id) { return(BadRequest("You need to be the admin in order to be able to make a change")); } string photoUrl = this._photoRepo.addPhoto(categoriePictureDto.file); if (photoUrl != null || photoUrl != "") { if (!this._db.addCategorieCoverPicture(categoriePictureDto, photoUrl)) { BadRequest("Couldn't upload photo"); } } return(photoUrl); }