示例#1
0
        public async Task <ActionResult> createCategorie([FromForm] CategorieToAddDto categorieToAddDto)
        {
            if (categorieToAddDto.userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized("You are not the User cliamd to be"));
            }
            string title  = " ";
            Author author = new Author();

            author = await _db.getAuthorByUserId(categorieToAddDto.userId);

            if (author == null)
            {
                return(Unauthorized("You are not an author"));
            }
            string    imageUrl  = "";
            string    coverUrl  = "";
            PhotoRepo photoRepo = new PhotoRepo();

            if (categorieToAddDto.image != null)
            {
                imageUrl = photoRepo.addPhoto(categorieToAddDto.image);
            }
            else
            {
                imageUrl = "https://res.cloudinary.com/afdgadsfg/image/upload/v1620223243/dbujq3h-13f8d636-9028-474c-b0fa-2a588511ac5f_dcy4lo.png";
            }
            if (categorieToAddDto.cover != null)
            {
                coverUrl = photoRepo.addPhoto(categorieToAddDto.cover);
            }
            else
            {
                coverUrl = "https://res.cloudinary.com/afdgadsfg/image/upload/v1620222961/final-image-diverse-people-1_svynwn.jpg";
            }

            title = await _db.createCategorie(categorieToAddDto, imageUrl, coverUrl);



            if (title == " ")
            {
                return(BadRequest("didn't create"));
            }
            return(Ok(new{ categorieTitle = title }));
        }
示例#2
0
        public async Task <ActionResult> addCategorie(int adminId, CategorieToAddDto cocategorieToAddDto)
        {
            Admin admin = new Admin();

            admin = await _management.getAdmin(adminId);

            if (admin == null)
            {
                return(Unauthorized("You don't have the privlieges"));
            }
            User user = await _management.getUser(admin.userId);

            if (user == null)
            {
                return(BadRequest("user doesn't exist"));
            }
            if (user.id != (int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)))
            {
                return(Unauthorized("This is not your account"));
            }
            Categorie categorie = new Categorie();

            categorie = await _management.getCatergorieByTitle(cocategorieToAddDto.title);

            if (categorie != null)
            {
                return(BadRequest("categorie allready exists"));
            }
            await _management.addCategorie(cocategorieToAddDto.title);

            if (!await _management.saveAll())
            {
                return(BadRequest("something went wrong"));
            }

            return(Ok("Categorie added successfuly"));
        }
        public async Task <string> createCategorie(CategorieToAddDto categorieToAddDto, string imageUrl, string coverUrl)
        {
            Categorie categorie = new Categorie();

            if (!(((categorieToAddDto.title == "") || (categorieToAddDto.title == null))))
            {
                User user = await getUser(categorieToAddDto.userId);



                categorie.title    = categorieToAddDto.title;
                categorie.userId   = categorieToAddDto.userId;
                categorie.about    = categorieToAddDto.about;
                categorie.date     = DateTime.Now;
                categorie.coverUrl = coverUrl;
                categorie.imageUrl = imageUrl;



                await _dataContext.categories.AddAsync(categorie);

                this._dataContext.SaveChanges();
                Categorie categorieToReturn = this._dataContext.categories.FirstOrDefault(x => (
                                                                                              x.title == categorie.title &&
                                                                                              x.userId == categorie.userId &&
                                                                                              x.about == categorie.about &&
                                                                                              x.date == categorie.date &&
                                                                                              x.coverUrl == categorie.coverUrl &&
                                                                                              x.imageUrl == categorie.imageUrl
                                                                                              ));

                return(categorieToReturn.title);
            }

            return("");
        }