Esempio n. 1
0
        public ActionResult Index()
        {
            IUserService _us   = new UserServicesImpl(_context, _config);
            string       token = HttpContext.Session.GetString("token");

            if (_us.ValidateCurrentToken(token))
            {
                string username = _us.GetClaim(token, "userId");

                try
                {
                    string guid = Request.Query[Constants.FIID];
                    ViewBag.fiid = !string.IsNullOrEmpty(guid) ? guid : null;

                    IDownloadService _ds = new DownloadServicesImp(_context, _config);
                    var file             = _ds.GetFileManagement(guid);
                    if (file == null)
                    {
                        return(View(Constants.ERROR_PATH));
                    }
                    return(View(file));
                }
                catch (Exception e)
                {
                    return(View(Constants.ERROR_PATH));
                }
            }
            else
            {
                return(Redirect("~/Login"));
            }
        }
Esempio n. 2
0
        public ActionResult Index()
        {
            IUserService _us   = new UserServicesImpl(_context, _config);
            string       token = HttpContext.Session.GetString("token");

            if (_us.ValidateCurrentToken(token))
            {
                string username = _us.GetClaim(token, "userId");

                try
                {
                    ISearchService _ss = new SearchServiceImp(_context, _config);
                    var            vm  = _ss.SearchFiles("", "", "", username);

                    ViewBag.totalRecords = vm.Count;
                    ViewBag.files        = vm;
                    return(View("index", vm));
                }
                catch (Exception e)
                {
                    return(View(Constants.ERROR_PATH));
                }
            }
            else
            {
                return(Redirect("~/Login"));
            }
        }
Esempio n. 3
0
        public ActionResult Index()
        {
            IUserService _us   = new UserServicesImpl(_context, _config);
            string       token = HttpContext.Session.GetString("token");

            if (_us.ValidateCurrentToken(token))
            {
                string username = _us.GetClaim(token, "userId");

                try
                {
                    ViewBag.validExtension    = _config.GetSection(Constants.VALID_EXTENSION).Get <List <string> >();
                    ViewBag.maxFileSize       = _config.GetValue <int>(Constants.MAX_FILE_SIZE);
                    ViewBag.maxFileCount      = _config.GetValue <int>(Constants.MAX_FILE_COUNT);
                    ViewBag.maxLengthFileName = _config.GetValue <int>(Constants.MAX_LENGTH_FILE_NAME);
                    return(View());
                }
                catch (Exception e)
                {
                    return(View(Constants.ERROR_PATH));
                }
            }
            else
            {
                return(Redirect("~/Login"));
            }
        }
Esempio n. 4
0
        public ActionResult Index()
        {
            IUserService _us   = new UserServicesImpl(_context, _config);
            string       token = HttpContext.Session.GetString("token");

            if (_us.ValidateCurrentToken(token))
            {
                string username = _us.GetClaim(token, "userId");

                ISearchService _ss = new SearchServiceImp(_context, _config);
                ViewBag.files = _ss.GetFiles(username, null);

                ILogService _ls = new LogServicesImp(_context, _config);
                ViewBag.logs = _ls.getLog(username);

                IFolderService _fs = new FolderServicesImp(_context, _config);
                ViewBag.folders = _fs.GetAllFoldersByUserId(username);

                return(View());
            }
            else
            {
                return(Redirect("~/Login"));
            }
        }
Esempio n. 5
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            IUserService _us      = new UserServicesImpl(_context, _config);
            string       token    = HttpContext.Session.GetString("token");
            string       folderId = Request.Query["id"];

            if (_us.ValidateCurrentToken(token))
            {
                string username = _us.GetClaim(token, "userId");

                ISearchService _ss = new SearchServiceImp(_context, _config);
                ViewBag.files = _ss.GetFiles(username, folderId, 0);

                IFolderService _fs    = new FolderServicesImp(_context, _config);
                Folder         folder = _fs.GetFolderById(folderId);
                ViewBag.FolderName = folder.FolderName;
                ViewBag.FolderId   = folder.GUID;

                return(View());
            }
            else
            {
                return(Redirect("~/Login"));
            }
        }
Esempio n. 6
0
        public ActionResult Download()
        {
            IUserService _us    = new UserServicesImpl(_context, _config);
            string       token  = HttpContext.Session.GetString("token");
            string       action = Request.Query["action"];

            if (_us.ValidateCurrentToken(token))
            {
                string username = _us.GetClaim(token, "userId");

                try
                {
                    string           guid = Request.Query[Constants.FIID];
                    IDownloadService _ds  = new DownloadServicesImp(_context, _config);
                    var file = _ds.GetFileManagement(guid);
                    if (file == null)
                    {
                        return(View(Constants.ERROR_PATH));
                    }


                    if (action == "download")
                    {
                        Stream fileBytes = _ds.DownloadFile(username, file.GUID, file.FileUniqueName);
                        if (fileBytes == null)
                        {
                            return(View(Constants.ERROR_PATH));
                        }

                        return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, file.FileName));
                    }

                    else if (action == "delete")
                    {
                        if (_ds.DeleteFile(username, file.GUID, file.FileUniqueName))
                        {
                            return(Redirect("~/home"));
                        }
                        else
                        {
                            return(View(Constants.ERROR_PATH));
                        }
                    }
                    else
                    {
                        return(View(Constants.ERROR_PATH));
                    }
                }
                catch (Exception e)
                {
                    return(View(Constants.ERROR_PATH));
                }
            }
            else
            {
                return(Redirect("~/Login"));
            }
        }
Esempio n. 7
0
        public ActionResult Authenticate(string username, string password)
        {
            IUserService _us = new UserServicesImpl(_context, _config);

            if (_us.login(username, password) == null)
            {
                return(Json(new { success = false, message = "Login Failed" }));
            }
            else
            {
                HttpContext.Session.SetString("token", _us.generateToken(username));
                return(Json(new { success = true }));
            }
        }
Esempio n. 8
0
        public IActionResult Search()
        {
            IUserService _us   = new UserServicesImpl(_context, _config);
            string       token = HttpContext.Session.GetString("token");

            if (_us.ValidateCurrentToken(token))
            {
                string username = _us.GetClaim(token, "userId");

                try
                {
                    string fileName = Request.Query[Constants.FILE_NAME];
                    bool   upload   = Convert.ToBoolean(Request.Query["upload"]);
                    bool   download = Convert.ToBoolean(Request.Query["download"]);
                    bool   delete   = Convert.ToBoolean(Request.Query["delete"]);
                    string fromDate = Request.Query["fromDate"];
                    string toDate   = Request.Query["toDate"];


                    ILogService _ls = new LogServicesImp(_context, _config);

                    int logPerPage = _config.GetValue <int>(Constants.LOG_DISPLAY_PER_PAGE);

                    var logList = _ls.searchLog(username, fileName, upload, download, delete, fromDate, toDate);

                    ViewBag.fileName     = fileName;
                    ViewBag.upload       = upload;
                    ViewBag.download     = download;
                    ViewBag.delete       = delete;
                    ViewBag.fromDate     = fromDate;
                    ViewBag.toDate       = toDate;
                    ViewBag.totalRecords = logList.Count;
                    ViewBag.data         = logList;

                    return(View("Index"));
                }
                catch
                {
                    return(View(Constants.ERROR_PATH));
                }
            }
            else
            {
                return(Redirect("~/Login"));
            }
        }
Esempio n. 9
0
        public IActionResult CreateFolder()
        {
            IUserService _us   = new UserServicesImpl(_context, _config);
            string       token = HttpContext.Session.GetString("token");
            string       name  = Request.Query["name"];

            if (_us.ValidateCurrentToken(token))
            {
                string username = _us.GetClaim(token, "userId");

                IFolderService _fs = new FolderServicesImp(_context, _config);

                return(Json(new { success = _fs.CreateFolder(name, username) }));
            }
            else
            {
                return(Redirect("~/Login"));
            }
        }
Esempio n. 10
0
        public ActionResult Search()
        {
            IUserService _us   = new UserServicesImpl(_context, _config);
            string       token = HttpContext.Session.GetString("token");

            if (_us.ValidateCurrentToken(token))
            {
                string username = _us.GetClaim(token, "userId");

                try
                {
                    string fileName       = Request.Query[Constants.FILE_NAME];
                    string uploadDateFrom = Request.Query[Constants.UPLOAD_DATE_FROM];
                    string uploadDateTo   = Request.Query[Constants.UPLOAD_DATE_TO];


                    ViewBag.fileName       = !string.IsNullOrEmpty(fileName) ? fileName : null;
                    ViewBag.uploadDateFrom = !string.IsNullOrEmpty(uploadDateFrom) ? uploadDateFrom : null;
                    ViewBag.uploadDateTo   = !string.IsNullOrEmpty(uploadDateTo) ? uploadDateTo : null;


                    ISearchService _ss = new SearchServiceImp(_context, _config);
                    var            vm  = _ss.SearchFiles(fileName, uploadDateFrom, uploadDateTo, username);

                    ViewBag.totalRecords = vm.Count;
                    ViewBag.files        = vm;
                    return(View("index", vm));
                }
                catch (Exception e)
                {
                    return(View(Constants.ERROR_PATH));
                }
            }
            else
            {
                return(Redirect("~/Login"));
            }
        }
Esempio n. 11
0
        public ActionResult OnUpload(IList <IFormFile> files)
        {
            IUserService _us      = new UserServicesImpl(_context, _config);
            string       token    = HttpContext.Session.GetString("token");
            string       folderId = Request.Query["folderId"];

            if (_us.ValidateCurrentToken(token))
            {
                string username = _us.GetClaim(token, "userId");

                try
                {
                    IUploadService _uploadservice = new UploadServicesImp(_context, _config);

                    bool validate = _uploadservice.ValidationFiles(files);

                    if (!validate)
                    {
                        return(Json(new { success = "false", message = "Unable to upload file" }));
                    }

                    if (!_uploadservice.UploadFile(username, files, folderId))
                    {
                        return(Json(new { success = "false", message = "Unable to upload file" }));
                    }

                    return(Json(new { success = "true" }));
                }
                catch (Exception e)
                {
                    return(Json(new { success = "false", message = "Unable to upload file" }));
                }
            }
            else
            {
                return(Json(new { success = "false", message = "Unable to upload file" }));
            }
        }