Exemplo n.º 1
0
 public IActionResult OnPost()
 {
     if (ModelState.IsValid)
     {
         var subscription  = SubscriptionEmail.ToModel();
         var isSuccessfull = _subscriptionsService.Create(subscription);
         if (isSuccessfull)
         {
             return(RedirectToPage("Index"));
         }
         else
         {
             Message = $"There is already a subscription with the email: {subscription.Email}";
             return(Page());
         }
     }
     return(Page());
 }
 public ActionResult <SubscriptionDTO> Create([FromBody] SubscriptionDTO subscription)
 {
     try
     {
         if (subscription != null && ModelState.IsValid)
         {
             SubscriptionDTO created = subscriptionsService.Create(subscription);
             return(Ok(subscription));
         }
         else
         {
             return(BadRequest($"Incorrect data received. For model reference: {ModelState.ValidationState}"));
         }
     }
     catch (Exception exc)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError,
                           $"Something went wrong: {exc.Message}"));
     }
 }
Exemplo n.º 3
0
 public IActionResult OnPost()
 {
     if (ModelState.IsValid)
     {
         var subscription  = SubscriptionEmail.ToModel();
         var isSuccessfull = _subscriptionsService.Create(subscription);
         if (isSuccessfull)
         {
             OnGet();
             return(Page());
         }
         else
         {
             OnGet();
             MessageAboutSubscribing = $"There is already a subscription with the email: {subscription.Email}";
             return(Page());
         }
     }
     return(Page());
 }