public ActionResult Newsletter(string[] selectedCategories) { if (selectedCategories == null || !selectedCategories.Any()) { return(RedirectToAction("Newsletter", routeValues: new { message = Messages.NewsletterSubscription })); } var categories = string.Join(",", selectedCategories); var newletterVm = new NewsletterViewModel { Active = true, Subscription = categories, UserId = User.Identity.GetUserId() }; var newsletter = _mapper.Map <NewsletterExtend>(newletterVm); var userId = User.Identity.GetUserId(); var newsletterValue = _newsletterService.GetSingle(i => i.UserId == userId); if (newsletterValue != null) { newsletterValue.Subscription = newletterVm.Subscription; newsletterValue.Active = newletterVm.Active; _newsletterService.Update(newsletterValue); } else { _newsletterService.Create(newsletter); } return(RedirectToAction(ProfileControllerAction.Index, routeValues: new { message = Messages.NewsletterSubscriptionConfirmation })); }
public ActionResult Edit(Newsletter newsletter) { if (ModelState.IsValid) { newsletterService.Update(newsletter); return(RedirectToAction("Index")); } return(View(newsletter)); }