Exemplo n.º 1
0
        public ActionResult Index(ConfigEntity model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // Update model
                    model.AdminIp = Request.UserHostAddress;

                    // Handle blob files
                    foreach (string inputName in Request.Files)
                    {
                        var file = Request.Files[inputName];
                        if (file.ContentLength > 0)
                        {
                            string fileFullName = Path.GetFileName(file.FileName);

                            CloudBlockBlob blob = AzureHelper.GetCloudBlob("CitizenPortal", fileFullName);
                            blob.UploadFromStream(file.InputStream);

                            PropertyInfo prop = model.GetType().GetProperty(inputName + "Url");
                            prop.SetValue(model, blob.Uri.ToString());
                        }
                    }

                    // Update Azure Table
                    AzureHelper.GetCloudTable("CitizenPortal").Execute(TableOperation.InsertOrReplace(model));

                    // Renew cache
                    CacheHelper.ClearAll();
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("error", ex.Message);
                }
            }

            return(View(model));
        }