public IActionResult Register(User user) { if (!ModelState.IsValid) { return(View(user)); } try { if (user.isAuthor) { Author author = new Author(); author.Name = user.Name; author.Login = user.Login; author.Password = user.Password; authorRepository.Create(author); } else { Subscriber subscriber = new Subscriber(); subscriber.Name = user.Name; subscriber.Login = user.Login; subscriber.Password = user.Password; subscriberRepository.Create(subscriber); } return(RedirectToAction("Index", "Home")); } catch { return(View(user)); } }
public async Task<ActionResult> Subscribe(Subscriber subscriber) { try { var subscriberRepo = new SubscriberRepository(); subscriberRepo.Create(new Subscriber { Email = subscriber.Email, DateRegistered = DateTime.UtcNow }); return Json(new { success = true, responseText = "Added." }, JsonRequestBehavior.AllowGet); } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; return Json(new { success = false, responseText = ex.Message }, JsonRequestBehavior.AllowGet); } }
public async Task <ActionResult> Subscribe(Subscriber subscriber) { try { var subscriberRepo = new SubscriberRepository(); subscriberRepo.Create(new Subscriber { Email = subscriber.Email, DateRegistered = DateTime.UtcNow }); return(Json(new { success = true, responseText = "Added." }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; return(Json(new { success = false, responseText = ex.Message }, JsonRequestBehavior.AllowGet)); } }