public IActionResult DataReaderConfig(ConfigurationViewModel configuration)
        {
            if (string.IsNullOrEmpty(configuration.SelectedInputType))
            {
                return(View("Error", "You have selected nothing"));
            }
            else
            {
                var randomView = new RandomInputViewModel();
                var fileView   = new FileInputViewModel();

                var k = configuration.SelectedInputType;
                switch (k)
                {
                case "Random": return(RedirectToAction("RandomInput", randomView));

                case "Manually": return(RedirectToAction("NumInput", fileView));

                case "FromFile": return(RedirectToAction("FileInput", fileView));

                default:
                    break;
                }
                return(RedirectToAction("Error"));
            }
        }
Esempio n. 2
0
        public IViewComponentResult Invoke(
            string aspFor,
            string label,
            string?hintText,
            string?cssClass
            )
        {
            var model = ViewData.Model;

            var property = model.GetType().GetProperty(aspFor);

            var hasError     = ViewData.ModelState[property?.Name]?.Errors?.Count > 0;
            var errorMessage = hasError ? ViewData.ModelState[property?.Name]?.Errors[0].ErrorMessage : null;

            var fileInputViewModel = new FileInputViewModel(
                aspFor,
                aspFor,
                label,
                cssClass,
                hintText,
                errorMessage,
                hasError
                );

            return(View(fileInputViewModel));
        }
        public async Task <IActionResult> UploadFileAsync([FromForm] FileInputViewModel model)
        {
            var status  = false;
            var message = string.Empty;
            var Result  = new Res();
            await Task.Run(() => _documentService.UploadFile(model, out status, out message));

            if (status)
            {
                Result.Status  = status;
                Result.Message = message;
            }
            else
            {
                Result.Data    = null;
                Result.Status  = status;
                Result.Message = message;
            }
            return(Ok(Result));
        }
 public ActionResult FileInput(FileInputViewModel fileInput)
 {
     fileInput.Schedule.Add(new ScheduleViewModel());
     return(View(fileInput));
 }
        public ActionResult FileInput(IFormFile postedFile)
        {
            if (postedFile == null)
            {
                return(View("Error", "You have not chosen a file"));
            }

            _ = this.Environment.WebRootPath;
            _ = this.Environment.ContentRootPath;

            string path = Path.Combine(this.Environment.WebRootPath, "UploadedFiles");

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

            string fileName = Path.GetFileName(postedFile.FileName);

            using (FileStream stream = new FileStream(Path.Combine(path, fileName), FileMode.Create))
            {
                postedFile.CopyTo(stream);
                string uploadedFile = fileName;

                ViewBag.Message += string.Format("<b>{0}</b> uploaded.<br />", fileName);
            }

            List <int> list = new List <int>();

            using (FileStream stream = new FileStream(Path.Combine(path, fileName), FileMode.Open))
            {
                using (TextReader sr = new StreamReader(stream, Encoding.UTF8))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        string[] arr = line.Trim().Split(',', ' ');
                        foreach (var item in arr)
                        {
                            try
                            {
                                list.Add(Convert.ToInt32(item));
                            }
                            catch (Exception ex)
                            {
                                return(View("Error", "All values must not be 0 or negative or not integer"));
                            }
                        }
                    }
                }
            }
            FileInputViewModel fileInput = new FileInputViewModel();

            fileInput.Schedule.Add(new ScheduleViewModel());
            int id = 1;

            for (int i = 0; i < list.Count; i += 2)
            {
                fileInput.Schedule[0].operations.Add(new OperationViewModel()
                {
                    Id = id++, Deadline = list[i], Penalty = list[i + 1]
                });
            }

            return(View(fileInput));
        }
        public void UploadFile(FileInputViewModel model, out bool status, out string message)
        {
            try
            {
                if (model.File == null || model.File.Length == 0)
                {
                    status  = false;
                    message = MesssageContant.FILE_NULL;
                }
                else
                {
                    var libData = _libraryService.GetLibraryById(model.LibraryId);
                    if (libData != null)
                    {
                        var rootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/");

                        if (!Directory.Exists(rootPath + libData.Name))
                        {
                            var folder = Directory.CreateDirectory(rootPath + libData.Name);
                        }
                        var newpath = Path.Combine(rootPath, libData.Name);

                        var path = Path.Combine(newpath, model.File.GetFilename());

                        //string[] typeFile = new[] { Path.GetExtension(model.FileUrl.FileName) };

                        if (!Validate.CheckFileType(path))
                        {
                            status  = false;
                            message = MesssageContant.CHECK_FILE;
                        }
                        else
                        {
                            using (var stream = new FileStream(path, FileMode.Create))
                            {
                                model.File.CopyToAsync(stream);
                            }
                            var dto = new DocumentViewModel
                            {
                                LibraryId   = model.LibraryId,
                                FileUrl     = path,
                                Name        = model.File.GetFilename(),
                                Description = model.Description
                            };
                            var data = Insert(dto);
                            status  = data.Status;
                            message = MesssageContant.UPLOAD_SUCCESS;
                        }
                    }
                    else
                    {
                        status  = false;
                        message = MesssageContant.UPLOAD_FAIL;
                    }
                }
            }
            catch (Exception ex)
            {
                status  = true;
                message = "Upload Failed: " + ex.Message;
            }
        }
Esempio n. 7
0
 public ActionResult FileInput(FileInputViewModel fileInput)
 {
     fileInput.Schedule.Add(new ScheduleViewModel());
     fileInput.NumberOfPenalties = 0;
     return(View(fileInput));
 }