Exemple #1
0
        public async Task <ActionResult> CreateAd(AdCreateModel model)
        {
            User user = await _userManager.GetUserAsync(User);

            _adService.CreateAd(model, user.Id);

            return(RedirectToAction("Index", "Home"));
        }
        public async Task <IActionResult> OnPost()
        {
            Input.CategoryId  = int.Parse(Request.Form["CategoryId"].ToString());
            Input.ConditionId = Int32.Parse(Request.Form["ConditionId"].ToString());
            var picturesPaths = await SavePictures(Input);

            await adService.CreateAd(Input, picturesPaths);

            return(Redirect("/"));
        }
Exemple #3
0
        public IActionResult Create([FromBody] Ad adModel)
        {
            if (adModel == null || string.IsNullOrEmpty(adModel.Id))
            {
                return(BadRequest(new { message = "Bad Json" }));
            }
            var ad = _adservice.CreateAd(adModel);

            return(Ok(ad));
        }
Exemple #4
0
        public async Task <IActionResult> CreateAd(CreateAdViewModel model)
        {
            var categories = await categoryService.GetAll();

            model.Categories = this.mapper.Map <List <CategoryViewModel> >(categories);
            if (ModelState.IsValid)
            {
                var user = await userManager.GetUserAsync(httpContextAccessor.HttpContext.User);

                var creatAdDto = this.mapper.Map <CreateAdDTO>(model);
                var result     = await adService.CreateAd(creatAdDto, user.Id);
            }
            return(this.View(model));
        }
Exemple #5
0
        public IActionResult CreateAd([FromBody] AdDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Errors()));
            }
            model.Defaults(_configuration);
            if (_jsonDataService.IsValidCategory(model.AdCategoryId))
            {
                return(BadRequest(nameof(model.AdCategoryId)));
            }
            if (_jsonDataService.IsValidCallingCode(int.Parse(model.UserPhoneCountryCode)))
            {
                return(BadRequest(nameof(model.UserPhoneCountryCode)));
            }
            model.GoogleStorageAdFileDto = new GoogleStorageAdFileDto();
            model.GoogleStorageAdFileDto.Values(_configuration, model.AttachedAssetsInCloudStorageId.Value);
            AdDto dto = _adService.CreateAd(model);

            return(Ok(dto));
        }
Exemple #6
0
        public IActionResult Create(CreateAdDto dto)
        {
            var result = _adService.CreateAd(dto);

            return(Json(result));
        }
Exemple #7
0
        public ActionResult AddNewAd(AdVM ad)
        {
            int id = User.Identity.GetUserId <int>();

            ad.Images = new List <ImageVM>();
            ad.UserId = id;

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <AdVM, AdDTO>()
                .ForMember(dest => dest.DateAdd, opt => opt.Ignore())
                .ForMember(dest => dest.CategoryName, opt => opt.Ignore())
                .ForMember(dest => dest.Category, opt => opt.Ignore())
                .ForMember(dest => dest.Kind, opt => opt.Ignore())
                .ForMember(dest => dest.KindName, opt => opt.Ignore())
                .ForMember(dest => dest.LocationName, opt => opt.Ignore())
                .ForMember(dest => dest.LocationNew, opt => opt.Ignore())
                .ForMember(dest => dest.User, opt => opt.Ignore());
                cfg.CreateMap <TagVM, TagDTO>();
                cfg.CreateMap <ImageVM, ImageDTO>();
            });
            //config.AssertConfigurationIsValid();
            var mapper = config.CreateMapper();
            // добавление изображений к модели если таковые имеются
            string idPath           = id.ToString();
            string idPathTemp       = Path.Combine(idPath, "Temp");
            string imagePath        = @"~\Images";
            string imagePathForSave = @"..\..\Images";
            string fullPath         = Path.Combine(imagePath, idPath);
            string fullPathForSave  = Path.Combine(imagePathForSave, idPath);
            string fullPathTemp     = Path.Combine(imagePath, idPathTemp);

            DirectoryInfo newImages = new DirectoryInfo(Server.MapPath(fullPathTemp));

            FileInfo[] addImages = newImages.GetFiles();
            if (addImages.Count() > 0)
            {
                foreach (FileInfo image in addImages)
                {
                    string name                 = image.Name;
                    string fullPathImage        = Path.Combine(fullPath, name);
                    string fullPathImageForSave = Path.Combine(fullPathForSave, name);
                    string fullPathTempImage    = Path.Combine(fullPathTemp, name);
                    //image.CopyTo(Server.MapPath(fullPath),false);
                    System.IO.File.Copy(Server.MapPath(fullPathTempImage), Server.MapPath(fullPathImage));
                    ImageVM newImage = new ImageVM();
                    newImage.Name           = name;
                    newImage.PathToOriginal = fullPathImageForSave;
                    newImage.PathToSmall    = fullPathImageForSave;
                    ad.Images.Add(newImage);
                }
                foreach (FileInfo image in addImages)
                {
                    image.Delete();
                }
            }

            var adCreate = mapper.Map <AdVM, AdDTO>(ad);

            adService.CreateAd(adCreate);
            return(View("SuccessfullNewAd"));
        }
Exemple #8
0
        //[AdminAuthorize(Permissions = "admin.ad.create")]
        public IActionResult Create(Moz.Biz.Dtos.Ads.CreateAdRequest request)
        {
            var resp = _adService.CreateAd(request);

            return(RespJson(resp));
        }
 public Ev Post(Ev ev)
 {
     return(_adService.CreateAd(ev));
 }