public async Task <IActionResult> UploadCV(List <IFormFile> files, [FromQuery] string apikey, [FromQuery] string userkey, [FromQuery] string consumerkey, [FromQuery] string token, [FromQuery] int userid)
        {
            //if (AuthenticateUser() == false)
            //{
            //    return Unauthorized();
            //}

            // if (apikey != "123")
            //  {
            //    return Unauthorized();
            // }

            //Do something with the files here.

            String FileName    = "";
            String NewFileName = "";
            String Extention   = "";

            string conStr = configuration.GetSection("Data").GetSection("ConntectionString").Value;

            RTS.JobStation.Models.Requestfile       RequestFileModel      = new RTS.JobStation.Models.Requestfile();
            RTS.JobStation.Controller.Requestfile   RequestFileController = new RTS.JobStation.Controller.Requestfile();
            MySql.Data.MySqlClient.MySqlConnection  con    = null;
            MySql.Data.MySqlClient.MySqlTransaction MyTran = null;



            try
            {
                con    = RTS.JobStation.DatabaseCommands.OpenConnection();
                MyTran = RTS.JobStation.DatabaseCommands.OpenTransaction(ref con);



                foreach (var file in files)
                {
                    if (file.Length > 0)
                    {
                        if (file == null || file.Length == 0)
                        {
                            return(Content("file not selected"));
                        }
                        FileName = file.FileName;

                        Extention   = System.IO.Path.GetExtension(file.FileName);
                        NewFileName = "cv-1510-" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.DayOfYear.ToString() + "-" + DateTime.Now.Hour.ToString() + "-" + DateTime.Now.Minute.ToString() + "-" + DateTime.Now.Second.ToString() + "-" + DateTime.Now.Millisecond + "-" + DateTime.Now.Ticks.ToString() + "-gd-" + Guid.NewGuid().ToString() + Extention;
                        var path = Path.Combine(
                            Directory.GetCurrentDirectory(), "wwwroot", "cvs", NewFileName);

                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await file.CopyToAsync(stream);
                        }
                    }
                }

                return(Ok(NewFileName));
            }
            catch (Exception ex)
            {
                return(StatusCode(500));
            }
            finally
            {
                RTS.JobStation.DatabaseCommands.CloseTransaction(ref MyTran);
                RTS.JobStation.DatabaseCommands.CloseConnection(ref con);
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> UploadDocument(List <IFormFile> files, int candidateID, int RequestID)
        {
            //Do something with the files here.

            String FileName    = "";
            String NewFileName = "";
            String Extention   = "";

            string conStr = configuration.GetSection("Data").GetSection("ConntectionString").Value;

            RTS.JobStation.Models.Requestfile       RequestFileModel      = new RTS.JobStation.Models.Requestfile();
            RTS.JobStation.Controller.Requestfile   RequestFileController = new RTS.JobStation.Controller.Requestfile();
            MySql.Data.MySqlClient.MySqlConnection  con    = null;
            MySql.Data.MySqlClient.MySqlTransaction MyTran = null;



            try
            {
                con    = RTS.JobStation.DatabaseCommands.OpenConnection();
                MyTran = RTS.JobStation.DatabaseCommands.OpenTransaction(ref con);
                foreach (var file in files)
                {
                    if (file.Length > 0)
                    {
                        if (file == null || file.Length == 0)
                        {
                            return(Content("file not selected"));
                        }
                        FileName = file.FileName;

                        Extention   = System.IO.Path.GetExtension(file.FileName);
                        NewFileName = Guid.NewGuid().ToString() + Extention;
                        var path = Path.Combine(
                            Directory.GetCurrentDirectory(), "wwwroot", "cvs", NewFileName);

                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await file.CopyToAsync(stream);
                        }
                    }


                    RequestFileModel.UserID    = Int32.Parse(Request.Headers["UserID"].ToString());
                    RequestFileModel.FileName  = FileName;
                    RequestFileModel.FileURL   = NewFileName;
                    RequestFileModel.MIMEType  = Extention;
                    RequestFileModel.RequestID = RequestID;
                    RequestFileModel.UpdatedBy = Request.Headers["UserID"];
                    RequestFileModel.UpdatedOn = DateTime.Now;

                    RequestFileController.Insert(RequestFileModel, ref con, ref MyTran);
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(500));
            }
            finally
            {
                RTS.JobStation.DatabaseCommands.CloseTransaction(ref MyTran);
                RTS.JobStation.DatabaseCommands.CloseConnection(ref con);
            }
        }
        public async Task <IActionResult> UploadDocuments(List <IFormFile> files, [FromForm] string CandidateID, [FromForm] string FileTypeID, [FromForm] string FileDisplayName, [FromForm] string RequestID, [FromQuery] string apikey, [FromQuery] string userkey, [FromQuery] string consumerkey, [FromQuery] string token, [FromQuery] int userid)
        {
            //if (AuthenticateUser() == false)
            //{
            //    return Unauthorized();
            //}

            // if (apikey != "123")
            //  {
            //    return Unauthorized();
            // }

            //Do something with the files here.



            String FileName    = "";
            String NewFileName = "";
            String Extention   = "";

            string conStr = configuration.GetSection("Data").GetSection("ConntectionString").Value;

            RTS.JobStation.Models.Requestfile       RequestFileModel      = new RTS.JobStation.Models.Requestfile();
            RTS.JobStation.Controller.Requestfile   RequestFileController = new RTS.JobStation.Controller.Requestfile();
            MySql.Data.MySqlClient.MySqlConnection  con    = null;
            MySql.Data.MySqlClient.MySqlTransaction MyTran = null;



            try
            {
                con    = RTS.JobStation.DatabaseCommands.OpenConnection();
                MyTran = RTS.JobStation.DatabaseCommands.OpenTransaction(ref con);


                if (FileDisplayName.ToString() == "undefined")
                {
                    FileDisplayName = "";
                }

                foreach (var file in files)
                {
                    if (file.Length > 0)
                    {
                        RTS.JobStation.Controller.Candidatedocument CandidateDocumentController = new RTS.JobStation.Controller.Candidatedocument();
                        RTS.JobStation.Models.Candidatedocument     CandidateDocumentModel      = new RTS.JobStation.Models.Candidatedocument();


                        RTS.JobStation.Controller.Requestfile RequestfileController = new RTS.JobStation.Controller.Requestfile();
                        RTS.JobStation.Models.Requestfile     RequestfileModel      = new RTS.JobStation.Models.Requestfile();

                        if (file == null || file.Length == 0)
                        {
                            return(Content("file not selected"));
                        }
                        FileName = file.FileName;

                        Extention   = System.IO.Path.GetExtension(file.FileName);
                        NewFileName = "cv-1510-" + DateTime.Now.Year.ToString() + "-" + DateTime.Now.DayOfYear.ToString() + "-" + DateTime.Now.Hour.ToString() + "-" + DateTime.Now.Minute.ToString() + "-" + DateTime.Now.Second.ToString() + "-" + DateTime.Now.Millisecond + "-" + DateTime.Now.Ticks.ToString() + "-gd-" + Guid.NewGuid().ToString() + Extention;
                        var path = Path.Combine(
                            Directory.GetCurrentDirectory(), "wwwroot", "cvs", NewFileName);

                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await file.CopyToAsync(stream);
                        }

                        //Save File Information to Database
                        CandidateDocumentModel.CandidateDocumentTypeID = Int32.Parse(FileTypeID);
                        CandidateDocumentModel.DateUploaded            = DateTime.Now;
                        CandidateDocumentModel.CandidateID             = Int32.Parse(CandidateID);
                        CandidateDocumentModel.FileName     = FileDisplayName.ToString().Replace(" ", "");
                        CandidateDocumentModel.FileLocation = NewFileName.ToString();
                        CandidateDocumentModel.MimeType     = Extention.ToString();
                        CandidateDocumentModel.UpdatedBy    = Request.Headers["userid"];
                        CandidateDocumentModel.UpdatedOn    = DateTime.Now;

                        if (Int32.Parse(RequestID) == 0)
                        {
                            CandidateDocumentController.Insert(CandidateDocumentModel, ref con, ref MyTran);
                        }
                        else
                        {
                            RequestfileModel.RequestID    = Int32.Parse(RequestID);
                            RequestfileModel.DateUploaded = DateTime.Now;
                            RequestfileModel.FileURL      = NewFileName.ToString().Replace(" ", "");
                            RequestfileModel.FileName     = FileDisplayName.ToString();
                            RequestfileModel.MIMEType     = Extention.ToString();
                            RequestfileModel.UserID       = Int32.Parse(Request.Headers["userid"]);
                            RequestfileModel.UpdatedBy    = Request.Headers["userid"];
                            RequestfileModel.UpdatedOn    = DateTime.Now;


                            RequestFileController.Insert(RequestfileModel, ref con, ref MyTran);
                            int RequestFileID = Int32.Parse(JobStation.DatabaseCommands.GetLastInsertedID(ref con, ref MyTran).ToString());

                            CandidateDocumentModel.WorkFlowRequestFileID = RequestFileID;
                            CandidateDocumentController.Insert(CandidateDocumentModel, ref con, ref MyTran);
                        }
                    }
                }

                return(Ok(NewFileName));
            }
            catch (Exception ex)
            {
                return(StatusCode(500));
            }
            finally
            {
                RTS.JobStation.DatabaseCommands.CloseTransaction(ref MyTran);
                RTS.JobStation.DatabaseCommands.CloseConnection(ref con);
            }
        }