Exemplo n.º 1
0
        public IActionResult Advert(Advert advert)
        {
            var userId = User.GetUserId();

            advert.UserId = userId;

            if (!ModelState.IsValid)
            {
                var vm = new AdvertViewModel()
                {
                    Advert     = advert,
                    Categories = _categoryService.GetCategories(),
                    Heading    = advert.Id == 0 ?
                                 "nowe ogłoszenie" :
                                 "edycja ogłoszenia"
                };

                return(View("Advert", vm));
            }

            if (advert.Id == 0)
            {
                _advertService.AddAdvert(advert);
            }
            else
            {
                _advertService.UpdateAdvert(advert, userId);
            }


            return(RedirectToAction("Adverts", "Advert"));
        }
Exemplo n.º 2
0
        public IActionResult AddAdvert([FromBody] AddAdvertModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (model.Name == null || model.TireSize == null || model.Condition == null ||
                model.Color == null || model.Description == null)
            {
                return(BadRequest());
            }

            var user = _userService.GetUserByID(Int32.Parse(HttpContext.User.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).FirstOrDefault().Value));

            try
            {
                _advertService.AddAdvert(model, user);

                return(Json(new { success = "true" }));
            }
            catch (Exception)
            {
                return(Json(new { success = "false" }));
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> AddAdvert(AddPaymentDto newAdvert)
        {
            ServiceResponse <GetPaymentDto> response = await _advertService.AddAdvert(newAdvert);

            if (response.Data == null)
            {
                return(NotFound(response));
            }
            return(Ok(response));
        }
Exemplo n.º 4
0
        public ActionResult AddAdvert(AddAdvertViewModel advertToAdd)
        {
            if (!ModelState.IsValid)
            {
                advertToAdd.Categories = GetCategories();
                return(View(advertToAdd));
            }
            var userId         = User.Identity.GetUserId();
            var advertToAddDto = _mapper.Map <AddAdvertViewModel, AddAdvertDto>(advertToAdd);
            var addedAdvert    = _advertService.AddAdvert(advertToAddDto, userId);

            if (addedAdvert == null)
            {
                return(View(advertToAdd));
            }
            return(RedirectToAction("GetUserAdverts", "Advert"));
        }