public EditSubResponse Handle(EditSub command) { var response = new EditSubResponse(); try { var sub = _subService.GetSubByName(command.Name); if (sub == null) { response.Error = "No sub found with the given name."; return(response); } var user = _membershipService.GetUserById(command.EditedByUserId); if (user == null) { response.Error = "Invalid user."; return(response); } if (!_subService.CanUserEditSub(user.UserName, sub.Name)) { response.Error = "You are not allowed to modify this sub."; return(response); } if (string.IsNullOrEmpty(command.Description)) { response.Error = "Please describe your sub."; return(response); } sub.Description = command.Description; sub.SidebarText = command.SidebarText; _subService.UpdateSub(sub); } catch (Exception ex) { // todo: log response.Error = ex.Message; } return(response); }
public async Task <ActionResult> Payment(int id) { var numb = _db.Amount(id); //ViewBag.Message = "Your contact page."; var email = (string)Session["Email"]; var paystackTransactionAPI = new PaystackTransaction("sk_test_4f260b0736ab1d07afe4642756c7868359abb180"); //var response = await paystackTransactionAPI.InitializeTransaction("*****@*****.**", 500000); var response = await paystackTransactionAPI.InitializeTransaction(email, numb, callbackUrl : "https://localhost:44367/"); if (response.status) { Response.AddHeader("Access-Control-Allow-Origin", "*"); Response.AppendHeader("Access-Control-Allow-Origin", "*"); var currentSub = sub.Get(email); if (currentSub == null) { sub.AddSub(id, email); } if (currentSub != null) { sub.UpdateSub(id, email); } Response.Redirect(response.data.authorization_url); } else { return(RedirectToAction("Error")); } return(RedirectToAction("Error")); }
public EditSubResponse Handle(EditSub command) { var response = new EditSubResponse(); try { var sub = _subService.GetSubByName(command.Name); if (sub == null) { response.Error = "No sub found with the given name."; return(response); } var user = _membershipService.GetUserById(command.EditedByUserId); if (user == null) { response.Error = "Invalid user."; return(response); } if (!_permissionService.CanUserManageSubConfig(user, sub.Id)) { response.Error = "You are not allowed to modify this sub."; return(response); } if (string.IsNullOrEmpty(command.Description)) { response.Error = "Please describe your sub."; return(response); } if (!string.IsNullOrEmpty(command.SubmissionText) && command.SubmissionText.Length > 1000) { response.Error = "The sidebar text cannot be greater than 1000 characters"; return(response); } if (!string.IsNullOrEmpty(command.SidebarText) && command.SidebarText.Length > 3000) { response.Error = "The submission text cannot be greater than 1000 characters"; return(response); } // only admins can determine if a sub is a default sub if (user.IsAdmin && command.IsDefault.HasValue) { sub.IsDefault = command.IsDefault.Value; } sub.Description = command.Description; sub.SidebarText = command.SidebarText; sub.SidebarTextFormatted = _markdownCompiler.Compile(command.SidebarText); sub.SubmissionText = command.SubmissionText; sub.SubmissionTextFormatted = _markdownCompiler.Compile(command.SubmissionText); sub.SubType = command.Type; sub.InAll = command.InAll; sub.Nsfw = command.Nsfw; _subService.UpdateSub(sub); } catch (Exception ex) { // todo: log response.Error = ex.Message; } return(response); }