// ModeratorSuscription/TrialSubscribe public async Task <ActionResult> TrialSubscribe() { try { //I. Check. string currentUserId = System.Web.HttpContext.Current.User.Identity.GetUserId(); if (currentUserId == null) { return(new HttpUnauthorizedResult()); } // II. Create a trial moderator subscription. if (ModelState.IsValid) { SubscriptionForModeratorDTO subscriptionDTO = new SubscriptionForModeratorDTO { UserProfileId = currentUserId, CourseCount = 1, SubscriptionPeriod = 7, IsTrial = true, IsApproved = true }; OperationDetails operationDetails = await SubscriptionForModeratorService.CreateAsync(subscriptionDTO, currentUserId); if (operationDetails.Succedeed) { return(PartialView("Report", operationDetails)); } else { ModelState.AddModelError(operationDetails.Property, operationDetails.Message); return(PartialView("Report", operationDetails)); } } // III. ViewBag.Message = "Non valid"; return(PartialView()); } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <string> EditModeratorSubscription(ModeratorSubscriptionViewModel Model) { string msg; string currentUserId = System.Web.HttpContext.Current.User.Identity.GetUserId(); if (currentUserId == null) { return("User isn't authorized!"); } try { if (ModelState.IsValid) { SubscriptionForModeratorDTO subscriptionDTO = new SubscriptionForModeratorDTO { SubscriptionForModeratorId = Model.ID, SubscriptionPeriod = Model.SubscriptionPeriod, CourseCount = Model.CourseCount, IsApproved = Model.IsApproved }; OperationDetails operationDetails = await SubscriptionForModeratorService.UpdateAsync(subscriptionDTO, currentUserId); if (operationDetails.Succedeed) { msg = "Saved Successfully"; } else { ModelState.AddModelError(operationDetails.Property, operationDetails.Message); msg = string.Format("Validation data not successfully. Error in {0}. Error message: {1}", operationDetails.Property, operationDetails.Message); } } else { msg = "Validation data not successfully"; } } catch (Exception ex) { msg = "Error occured:" + ex.Message; } return(msg); }