Esempio n. 1
0
        public RedirectToRouteResult Create(string topicName)
        {
            TopicModel topic = new TopicModel {
                TopicName = topicName
            };

            _topicRepository.Create(topic);
            _topicRepository.Save();

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 2
0
    /*==========================================================================================================================
    | HELPER: SAVE TO TOPIC
    \-------------------------------------------------------------------------------------------------------------------------*/
    /// <summary>
    ///   Adds the form values to a new <see cref="Topic"/>, and saves it to the <see cref="ITopicRepository"/>.
    /// </summary>
    private async Task SaveToTopic(ITopicBindingModel bindingModel) {

      /*------------------------------------------------------------------------------------------------------------------------
      | Establish variables
      \-----------------------------------------------------------------------------------------------------------------------*/
      bindingModel.ContentType  = bindingModel.GetType().Name.Replace("BindingModel", "");
      bindingModel.Key          = bindingModel.ContentType + "_" + DateTime.Now.ToString("yyyyMMddHHmmss");

      /*------------------------------------------------------------------------------------------------------------------------
      | Validate Topic Parent
      \-----------------------------------------------------------------------------------------------------------------------*/
      var       parentKey       = "Administration:Licenses";
      var       parentTopic     = TopicRepository.Load(parentKey);

      /*------------------------------------------------------------------------------------------------------------------------
      | Map binding model to new topic
      \-----------------------------------------------------------------------------------------------------------------------*/
      var       topic           = await _reverseMappingService.MapAsync(bindingModel);
      var       errorMessage    = $"The topic '{parentKey}' could not be found. A root topic to store forms to is required.";

      /*------------------------------------------------------------------------------------------------------------------------
      | Set Topic values
      \-----------------------------------------------------------------------------------------------------------------------*/
      topic.Parent              = parentTopic?? throw new Exception(errorMessage);
      topic.LastModified        = DateTime.Now;

      /*------------------------------------------------------------------------------------------------------------------------
      | Save form Topic
      \-----------------------------------------------------------------------------------------------------------------------*/
      TopicRepository.Save(topic);

    }
Esempio n. 3
0
        public int Save(TopicModel model)
        {
            SqlObject.CommandText = StoredProcedures.Topics.SaveTopics;
            int Isactive = model.IsActive.Equals("true") ? 1 : 0;

            SqlObject.Parameters = new object[]
            {
                model.TopicID,
                model.SubjectID,
                model.TopicName,
                model.TopicDescription,
                Isactive
            };
            return(_repository.Save());
        }
Esempio n. 4
0
    /*==========================================================================================================================
    | HELPER: SAVE TO TOPIC
    \-------------------------------------------------------------------------------------------------------------------------*/
    /// <summary>
    ///   Adds the form values to a new <see cref="Topic"/>, and saves it to the <see cref="ITopicRepository"/>.
    /// </summary>
    private async Task SaveToTopic(CoreContact bindingModel) {

      /*------------------------------------------------------------------------------------------------------------------------
      | Establish variables
      \-----------------------------------------------------------------------------------------------------------------------*/
      var contentType           = bindingModel.GetType().Name.Replace("BindingModel", "", StringComparison.Ordinal);

      bindingModel              = bindingModel with {
        ContentType             = contentType,
        Key                     = contentType + "_" + DateTime.Now.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture)
      };

      /*------------------------------------------------------------------------------------------------------------------------
      | Validate Topic Parent
      \-----------------------------------------------------------------------------------------------------------------------*/
      var       parentKey       = "Administration:Licenses";
      var       parentTopic     = TopicRepository.Load(parentKey);

      /*------------------------------------------------------------------------------------------------------------------------
      | Map binding model to new topic
      \-----------------------------------------------------------------------------------------------------------------------*/
      var       topic           = await _reverseMappingService.MapAsync(bindingModel).ConfigureAwait(true);
      var       errorMessage    = $"The topic '{parentKey}' could not be found. A root topic to store forms to is required.";

      /*------------------------------------------------------------------------------------------------------------------------
      | Set Topic values
      \-----------------------------------------------------------------------------------------------------------------------*/
      topic.Parent              = parentTopic?? throw new InvalidOperationException(errorMessage);
      topic.LastModified        = DateTime.Now;

      /*------------------------------------------------------------------------------------------------------------------------
      | Save form Topic
      \-----------------------------------------------------------------------------------------------------------------------*/
      TopicRepository.Save(topic);

    }
Esempio n. 5
0
    public async Task<IActionResult> IndexAsync(PaymentFormBindingModel bindingModel) {

      /*------------------------------------------------------------------------------------------------------------------------
      | Validate invoice
      \-----------------------------------------------------------------------------------------------------------------------*/
      // ### HACK JJC20200408: One might reasonably expect for the [Remote] model validation attribute to be validated as part
      // of ModelState.IsValid, but it doesn't appear to be. As a result, it needs to be revalidated here.
      var invoice               = GetInvoice(bindingModel.InvoiceNumber);
      var invoiceAmount         = invoice.Attributes.GetDouble("InvoiceAmount", 1.00);
      if (invoice == null) {
        ModelState.AddModelError("InvoiceAmount", $"The invoice #{bindingModel.InvoiceNumber} is not valid.");
      }
      else if (invoiceAmount != bindingModel.InvoiceAmount) {
        ModelState.AddModelError(
          "InvoiceAmount",
          $"The invoice {bindingModel.InvoiceNumber} is correct, but doesn't match the expected invoice amount. Please " +
          $"recheck the amount owed. If it is confirmed to be correct, contact GoldSim."
        );
      }

      /*------------------------------------------------------------------------------------------------------------------------
      | Validate binding model
      \-----------------------------------------------------------------------------------------------------------------------*/
      if (!ModelState.IsValid) {
        return TopicView(await GetViewModel(bindingModel));
      }

      /*------------------------------------------------------------------------------------------------------------------------
      | Assemble and send Braintree transaction
      \-----------------------------------------------------------------------------------------------------------------------*/
      var braintreeGateway      = _braintreeConfiguration.GetGateway();
      var request               = new TransactionRequest {
        Amount                  = (decimal)bindingModel.InvoiceAmount,
        PurchaseOrderNumber     = bindingModel.InvoiceNumber.ToString(),
        PaymentMethodNonce      = bindingModel.PaymentMethodNonce,
        CustomFields            = new Dictionary<string, string> {
          { "cardholder"        , bindingModel.CardholderName },
          { "email"             , bindingModel.Email },
          { "company"           , bindingModel.Organization },
          { "invoice"           , bindingModel.InvoiceNumber.ToString() }
        },
        Options                 = new TransactionOptionsRequest {
          SubmitForSettlement   = true
        }
      };
      var result                = braintreeGateway.Transaction.Sale(request);

      /*------------------------------------------------------------------------------------------------------------------------
      | Send email
      \-----------------------------------------------------------------------------------------------------------------------*/
      await SendEmailReceipt(result, bindingModel);

      /*------------------------------------------------------------------------------------------------------------------------
      | Handle success
      \-----------------------------------------------------------------------------------------------------------------------*/
      if (result.IsSuccess()) {
        invoice.Attributes.SetDateTime("DatePaid", DateTime.Now);
        TopicRepository.Save(invoice);
        return Redirect("/Web/Purchase/PaymentConfirmation");
      }

      /*------------------------------------------------------------------------------------------------------------------------
      | Return to view to display ModelState errors
      \-----------------------------------------------------------------------------------------------------------------------*/
      return TopicView(await GetViewModel(bindingModel));

    }