Exemple #1
0
        public async Task <IActionResult> CreateOffer(CreateOfferSharedModel inputModel) // index post requsest for create
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Redirect("/Offer"));
            }

            var imgSize = inputModel.CreateOfferModel.Photo.Length;

            if (imgSize >= 1048576)
            {
                return(this.Redirect("/Offer"));
            }

            var offerInput = inputModel.CreateOfferModel;
            var categoryId = await this.categoryService.GetIdByNameAsync(offerInput.CategotyName);

            offerInput.CategotyName = categoryId;
            offerInput.CreatorId    = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            var photoUrl = await this.cloudinaryService.UploadPhotoAsync(
                offerInput.Photo,
                $"{userId}-{offerInput.Name}",
                GlobalConstants.CloudFolderForOfferPhotos);

            offerInput.PicUrl = photoUrl;

            await this.offerService.CreateOfferAsync(offerInput);

            return(this.Redirect("/"));
        }
Exemple #2
0
        public async Task <IActionResult> Index()
        {
            var categories = await this.categoryService.GetAllCategoryViewModelsAsync();

            CreateOfferSharedModel viewModel = new CreateOfferSharedModel();

            viewModel.CreateOfferViewModel = new CreateOfferViewModel(categories);
            return(this.View(viewModel));
        }