예제 #1
0
        public async Task <OperationDetail> CreateAsync(IFormCollection formCode)
        {
            Category category = null;

            if (formCode.Files.Count < 1)
            {
                category = new Category()
                {
                    Title        = formCode.ToList()[1].Value,
                    PreviewImage = null,
                };
            }
            else
            {
                category = new Category()
                {
                    Title        = formCode.ToList()[0].Value,
                    PreviewImage = await _fileService.Save(await _imageService.ImageResizeAsync(formCode.Files[0], ".png", 20000, 300, 300)),
                };
            }

            var res = await this.CreateAsync(category);

            return(res);
        }
예제 #2
0
        public async Task <IActionResult> UploadImage(IFormCollection model)
        {
            bool isRoomie = bool.Parse((model.ToList().Find(x => x.Key == "isRoomie").Value.ToString()));

            int id = int.Parse((model.ToList().Find(x => x.Key == "id").Value.ToString()));

            await _pictureGateway.UploadPicture(model.Files[0], id, isRoomie);

            return(Ok());
        }
        public static Dictionary <string, string> ColletionToDictionary(IFormCollection formCollection)
        {
            var dicts = new Dictionary <string, string>();

            foreach (var k in formCollection.ToList())
            {
                dicts.Add(k.Key, k.Value.ToString());
            }

            return(dicts);
        }
        public static JObject ColletionToJSON(IFormCollection formCollection)
        {
            var jobject = new JObject();

            foreach (var k in formCollection.ToList())
            {
                jobject.Add(k.Key, k.Value.ToString());
            }

            return(jobject);
        }
예제 #5
0
        public ActionResult Index(IFormCollection fc, CheckModel m)
        {
            foreach (var item in fc.ToList())
            {
                //       if(item==true)
                //    {

                //    }
                //    else
                //    {

                //    }
            }
            return(View());
        }
예제 #6
0
        public async Task <IActionResult> GravarNovoItem(IFormCollection formCollection)
        {
            var idServidor = HttpContext.Session.GetInt32("idServidor").Value;
            var idUsuario  = HttpContext.Session.GetInt32("idUsuario").Value;
            var lista      = formCollection.ToList();
            var valores    = new Dictionary <string, string>();

            foreach (var item in lista)
            {
                valores.Add(item.Key, item.Value[0]);
            }
            await _tabelaCore.CarregarAsync(valores["Tabela"], valores["Schema"], valores["Database"], idServidor);

            await _tabelaCore.InserirRegistroAsync(valores, idUsuario);

            return(RedirectToAction("Index", new { database = valores["Database"], schema = valores["Schema"], tabela = valores["Tabela"] }));
        }
예제 #7
0
        public async Task <IActionResult> Filtrar(IFormCollection formCollection)
        {
            var idServidor = HttpContext.Session.GetInt32("idServidor").Value;
            var lista      = formCollection.ToList();
            var valores    = new Dictionary <string, string>();

            foreach (var item in lista)
            {
                valores.Add(item.Key, item.Value[0]);
            }

            await _tabelaCore.CarregarAsync(valores["Tabela"], valores["Schema"], valores["Database"], idServidor);

            await _tabelaCore.PesquisarRegistrosAsync(valores);

            ViewBag.Title = valores["Tabela"];

            return(Json(_tabelaCore));
        }
예제 #8
0
        public ActionResult Update(IFormCollection keyValuePairs)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    ModelState.AddModelError(string.Empty, "Modelstate is invalid");
                    return(RedirectToAction(nameof(Index)));
                }


                var settings = new List <Setting>();
                var items    = keyValuePairs.ToList();

                for (var i = 0; i < items.Count() - 1; i++)
                {
                    var item    = items[i];
                    var setting = this.repository.Setting.Find(m => m.Key.Equals(item.Key));
                    if (!setting.Value.Equals(item.Value))
                    {
                        setting.Value = item.Value;

                        settings.Add(setting);
                    }
                }

                this.repository.Setting.UpdateRange(settings);
                this.repository.SaveAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
                this.logger.LogWarn(e.Message);
                return(RedirectToAction(nameof(Index)));
            }
        }
예제 #9
0
        // Create and store each answer from the user into the DB.
        public async Task CreateAndStoreFormAnswersAsync(IFormCollection passedForm, UserType passedVisitorType)
        {
            var userGuid = Guid.NewGuid();

            // Gather all the choices so we can get the text for their answer later on. Create a list of Answers for
            // iteration later on.
            var listOfChoices = _dbContext.SurveyChoices.AsQueryable();
            var listOfAnswers = new List <SurveyAnswer>();

            // Answer is going to be a key,value pair. Key will be the QuestionId while the value is the ChoiceId.
            foreach (var formChoice in passedForm.ToList())
            {
                // _ is to discard the value as it is not needed. We are only curious if the value is a GUID which would
                // correspond a question being present at that enumeration.
                if (Guid.TryParse(formChoice.Key, out _))
                {
                    // Create the answer objects after parsing the form submission.
                    var userAnswer = "";
                    if (formChoice.Value.Count == 1)
                    {
                        //Only need to check if this is a text input field since the value can only of a count of one.
                        if (Guid.TryParse(formChoice.Value, out _))
                        {
                            userAnswer = listOfChoices.Where(x => x.Id == new Guid(formChoice.Value)).First().Text;
                        }
                        else
                        {
                            userAnswer = formChoice.Value;
                        }

                        var formAnswer = new SurveyAnswer
                        {
                            Id         = Guid.NewGuid(),
                            QuestionId = new Guid(formChoice.Key),
                            Answer     = userAnswer,
                            UserId     = userGuid,
                            UserType   = passedVisitorType
                        };

                        listOfAnswers.Add(formAnswer);
                    }
                    else if (formChoice.Value.Count > 1)
                    {
                        foreach (var choice in formChoice.Value)
                        {
                            // Want to make sure that if there are no answers for a checkbox that we don't input
                            // the hidden values that are being used for the URL calculation.
                            if (!choice.Equals("hiddenCheckbox", StringComparison.OrdinalIgnoreCase))
                            {
                                userAnswer = listOfChoices.Where(x => x.Id == new Guid(choice)).First().Text;
                                var formAnswer = new SurveyAnswer
                                {
                                    Id         = Guid.NewGuid(),
                                    QuestionId = new Guid(formChoice.Key),
                                    Answer     = userAnswer,
                                    UserId     = userGuid,
                                    UserType   = passedVisitorType
                                };

                                listOfAnswers.Add(formAnswer);
                            }
                        }
                    }
                }
            }

            // Validate the model being created before adding the answers to the DB
            foreach (var answer in listOfAnswers)
            {
                if (ModelState.IsValid)
                {
                    await _dbContext.SurveyAnswers.AddAsync(answer);

                    await _dbContext.SaveChangesAsync();
                }
            }
        }
예제 #10
0
        public async Task <IActionResult> Index(IFormFile file, IFormCollection form)
        {
            MeshResultModel model = new MeshResultModel();

            model.Original = new MeshDetailModel();
            model.Result   = new MeshDetailModel();

            string webRootPath        = _env.WebRootPath;
            string randomFilePath     = Path.GetRandomFileName().Replace(".", "");
            string relativeFolderPath = Path.Combine("models", "obj", randomFilePath);
            string newPath            = Path.Combine(webRootPath, relativeFolderPath);

            if (!Directory.Exists(newPath))
            {
                Directory.CreateDirectory(newPath);
            }

            var urlPath = relativeFolderPath.Replace("\\", "/");

            model.Original.RelativeFolderPath = urlPath;
            model.Result.RelativeFolderPath   = urlPath;

            List <ScriptParameterFilter> lstScriptParams = new List <ScriptParameterFilter>();

            if (form != null && form.Any())
            {
                foreach (var keyValuePair in form.ToList())
                {
                    var kp = keyValuePair.Key.Split("#");
                    if (kp.Length == 2)
                    {
                        var sp = lstScriptParams.FirstOrDefault(a => a.FilterName == kp[0]);
                        if (sp == null)
                        {
                            sp            = new ScriptParameterFilter();
                            sp.FilterName = kp[0];
                            lstScriptParams.Add(sp);
                        }

                        if (sp.FilterParameter == null)
                        {
                            sp.FilterParameter = new Dictionary <string, string>();
                        }

                        sp.FilterParameter.Add(kp[1], keyValuePair.Value);
                    }
                }
            }

            if (file?.Length > 0)
            {
                model.Original.Filename = file.FileName;
                var originalFilePath = await saveOriginalFile(file, newPath);

                HttpClient hc = new HttpClient();
                hc.Timeout = TimeSpan.FromHours(2);

                Client        c             = new Client(_appSettings.RestApiUrl, hc);
                FileParameter fileParameter = new FileParameter(file.OpenReadStream(), file.FileName, file.ContentType);

                JobResult jobResult = null;

                try
                {
                    jobResult = await c.UploadJobAsync(fileParameter, JsonConvert.SerializeObject(lstScriptParams), form.FirstOrDefault().Value, form.FirstOrDefault(a => a.Key == "selectedOutputFormat").Value);
                }
                catch (Exception e)
                {
                    //TODO: Schöner
                    ViewBag.Error = "Error at uploading.";
                    ViewBag.Code  = e.ToString();

                    return(View("Error"));
                }

                if (jobResult != null && jobResult.ResultCode.Number != JobResultCodeNumber._0)
                {
                    //Job wasn't finished successfull
                    ViewBag.Error = jobResult.ResultCode.Message;
                    ViewBag.Code  = jobResult.ResultCode.Number;

                    return(View("Error"));
                }
                else if (jobResult != null)
                {
                    var resultFile = await c.DownloadJobFileResultAsync(jobResult.FileResultName, jobResult.JobId, newPath);

                    model.Result.Filename         = resultFile;
                    model.Result.AdditionalValues = new Dictionary <string, string>(jobResult.AdditionalData);
                    model.Result.FileSize         = jobResult.FileResultSize;
                    model.Result.NumberOfFaces    = jobResult.ResultNumberOfFaces;
                    model.Result.NumberOfVertices = jobResult.ResultNumberOfVertices;

                    model.ReducedBy         = jobResult.ReducedBy;
                    model.Original.FileSize = jobResult.FileInputSize;
                    ViewBag.Link            = $"{_appSettings.RestApiUrl}/api/DownloadLogForJob/{jobResult.JobId}";
                }
            }
            else
            {
                //no file selected
                ViewBag.Error = "Please select file";
                ViewBag.Code  = "";

                return(View("Error"));
            }

            return(View("~/Views/Visualization/ModelResultPreview.cshtml", model));
        }