Example #1
0
 public ActionResult Create(Form newForm)
 {
     _logger.LogDebug("Received Name: " + newForm.Name);
     _logger.LogDebug("Received Desc: " + newForm.Desc);
     try
     {
         // TODO: Add insert logic here
         //return RedirectToAction(nameof(Index));
         newForm.Id           = Guid.NewGuid().ToString();
         newForm.ClientId     = GetUserObjectId();
         newForm.Cors         = "";
         newForm.ApiKey       = Guid.NewGuid().ToString();
         newForm.FormTemplate = new FormTemplate(new MessageFormat());
         _formRepository.InsertOrUpdateForm(GetUserObjectId(), newForm);
         FormApiMap newFormApiMap = new FormApiMap();
         newFormApiMap.ApiKey = newForm.ApiKey;
         //newFormApiMap.ClientId = GetUserObjectId();
         //newFormApiMap.FormId = newForm.Id;
         //newFormApiMap.NumberOfRequests = 0;
         newFormApiMap.EmailInfo = newForm.FormTemplate;
         _apiFormRepository.InsertUpdateFormApiMap(GetUserObjectId(), newFormApiMap);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
        public void InsertUpdateFormApiMap(string clientId, FormApiMap formApiMap)
        {
            _logger.LogDebug($"Upserting FormApiMap with API key: {formApiMap.ApiKey}");
            CloudTable         apiFormTable             = GetAPIKeyTable();
            ApiFormTableEntity apiFormTableEntity       = formApiMap.ToApiForm();
            TableOperation     insertOrReplaceOperation = TableOperation.InsertOrReplace(apiFormTableEntity);

            apiFormTable.ExecuteAsync(insertOrReplaceOperation);
            _logger.LogDebug($"Finished Upserting FormApiMap with API key: {formApiMap.ApiKey}");
        }
Example #3
0
        public static FormApiMap ToApiMap(this ApiFormTableEntity apiFormEntity)
        {
            if (apiFormEntity == null)
            {
                return(null);
            }
            var result = new FormApiMap();

            result.EmailInfo = JsonConvert.DeserializeObject <EmailTemplateInfo>(apiFormEntity.EmailInfo);

            return(result);
        }
Example #4
0
        public static ApiFormTableEntity ToApiForm(this FormApiMap formApiMap)
        {
            if (formApiMap == null)
            {
                return(null);
            }
            var result = new ApiFormTableEntity(formApiMap.ApiKey);

            result.EmailInfo = JsonConvert.SerializeObject(formApiMap.EmailInfo);
            //result.NumberOfRequests = formApiMap.NumberOfRequests;
            return(result);
        }
Example #5
0
        public static FormApiMap ToApiMap(this ApiFormTableEntity apiFormEntity)
        {
            if (apiFormEntity == null)
            {
                return(null);
            }
            var result = new FormApiMap();

            result.ApiKey = apiFormEntity.RowKey;
            //result.NumberOfRequests = apiFormEntity.NumberOfRequests;
            result.EmailInfo = JsonConvert.DeserializeObject <FormTemplate>(apiFormEntity.EmailInfo);

            return(result);
        }
        public async Task <ActionResult> Edit(string id, FormTemplate editedFormTemplate)
        {
            try
            {
                //return View();
                Form editedForm = await _formRepository.GetForm(GetUserObjectId(), id);

                editedForm.FormTemplate = editedFormTemplate;
                _formRepository.InsertOrUpdateForm(GetUserObjectId(), editedForm);
                FormApiMap formApiMap = await _apiFormRepository.GetFormApiMap(editedForm.ApiKey);

                formApiMap.EmailInfo = editedFormTemplate;
                _apiFormRepository.InsertUpdateFormApiMap(GetUserObjectId(), formApiMap);
                ViewData["FormId"] = id;
                //return RedirectToAction(nameof(FormController.Index), "Form");
                return(View(editedFormTemplate));
            }
            catch
            {
                return(View());
            }
        }