// To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var userName = User.Identity.Name;

            service.CreateAdvertisement(Advertisement.Name, Advertisement.Description, Advertisement.Active, Advertisement.JobPositionId, userName);

            return(RedirectToPage("./Index"));
        }
Beispiel #2
0
 public IActionResult Create([Bind("AdvertisementType,AdvertisementLocation,AdvertisementUrl,AdvertisementImage,AdvertisementDescription,IsActive,StartDate,FinishDate,Id,Name,CreateDate,UpdateDate,CreatedBy,UpdateBy")] Advertisement advertisement)
 {
     if (ModelState.IsValid)
     {
         advertisement.CreatedBy  = "username";
         advertisement.CreateDate = DateTime.Now;
         advertisement.UpdateBy   = "username";
         advertisement.UpdateDate = DateTime.Now;
         advertisementservice.CreateAdvertisement(advertisement);
         advertisementservice.SaveAdvertisement();
         return(RedirectToAction("Index"));
     }
     return(View(advertisement));
 }
        public IActionResult Create(AdvertisementModel model)
        {
            var token = HttpContext.Session.GetString("agentId");

            if (!ModelState.IsValid)
            {
                ViewData["ErrorMessage"] = "Kayıt başarısız";
                return(View());
            }

            var agentId = Convert.ToInt32(token);
            var entitiy = _mapper.Map <Advertisement>(model);

            entitiy.AgentId = agentId;
            var result = _advertisementService.CreateAdvertisement(entitiy);

            return(RedirectToAction("Index", "Home"));
        }
        public async Task <ActionResult <AdvertisementDTO> > CreateUser([FromBody] AdvertisementDTO createAdvertisementResource)
        {
            // var validator = new CreateUserResourceValidator();
            // var validationResult = await validator.ValidateAsync(createUserResource);

            // if (!validationResult.IsValid)
            //     return BadRequest(validationResult.Errors); // this needs refining, but for demo it is ok

            var advertisementToCreate = _mapper.Map <AdvertisementDTO, Advertisement>(createAdvertisementResource);

            var newAdvertisement = await _advertisementService.CreateAdvertisement(advertisementToCreate);

            var advertisement = await _advertisementService.GetAdvertisementById(newAdvertisement.Id);

            var advertisementResource = _mapper.Map <Advertisement, AdvertisementDTO>(advertisement);

            return(Ok(advertisementResource));
        }
 public SaveUpdateResultModel <AdvertisementModel> CreateAdvertisement([FromBody] AdvertisementModel advertisement)
 {
     return(_mapper.Map <SaveUpdateResultModel <AdvertisementModel> >(
                _service.CreateAdvertisement(_mapper.Map <Advertisement>(advertisement))));
 }