Exemple #1
0
        public IActionResult AddImage([FromForm] GetEventImage image)
        {
            try
            {
                var result = new List <String>();
                if (image.Image != null)
                {
                    result = AddFiles.AddImages(image.Image, image.EventId);
                }

                EventImages eventimage = new EventImages();

                eventimage.EventId     = image.EventId;
                eventimage.Caption     = image.Caption;
                eventimage.Description = image.Description;
                eventimage.Author      = image.Author;

                var test = _service.AddImage(eventimage, result);
                if (test)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch
            {
                return(BadRequest());
            }
        }
        private void DataGrid_Drop(object sender, DragEventArgs e)
        {
            var files = e.Data.GetData(DataFormats.FileDrop) as string[];

            if (files == null)
            {
                return;
            }
            AddFiles?.Invoke(this, new FileListEventArgs(files));
        }
Exemple #3
0
        public static void GetFilesFromDb()
        {
            try
            {
                ulong       count  = dbCore.DbOps.GetFilesCount();
                const ulong PAGE   = 2500;
                ulong       offset = 0;

            #if DEBUG
                stopwatch.Restart();
            #endif
                while (dbCore.DbOps.GetFiles(out List <DbFile> files, offset, PAGE))
                {
                    if (files.Count == 0)
                    {
                        break;
                    }

                    UpdateProgress?.Invoke(null, $"Loaded file {offset} of {count}", (long)offset, (long)count);

                    AddFiles?.Invoke(files);

                    offset += PAGE;
                }
            #if DEBUG
                stopwatch.Stop();

                Console.WriteLine("Core.GetFilesFromDb(): Took {0} seconds to get all files from the database",
                                  stopwatch.Elapsed.TotalSeconds);
            #endif

                Finished?.Invoke();
            }
            catch (ThreadAbortException) {}
            catch (Exception ex)
            {
                if (Debugger.IsAttached)
                {
                    throw;
                }

                Failed?.Invoke($"Exception {ex.Message}\n{ex.InnerException}");
            #if DEBUG
                Console.WriteLine("Exception {0}\n{1}", ex.Message, ex.InnerException);
            #endif
            }
        }
Exemple #4
0
        public IActionResult Create([FromForm] GetEmployee emp)
        {
            try
            {
                string res = "";
                if (emp.EmpProfilePicture != null)
                {
                    // add profile picture
                    res = AddFiles.AddImage(emp.EmpProfilePicture, emp.EmpId);
                }
                Hash hash = new Hash();
                emp.EmpPassword = hash.HashPassword(emp.EmpPassword);

                Employee employee = new Employee();
                employee.EmpId             = emp.EmpId;
                employee.EmpEmail          = emp.EmpEmail;
                employee.EmpPassword       = emp.EmpPassword;
                employee.EmpName           = emp.EmpName;
                employee.EmpContact        = emp.EmpContact;
                employee.EmpAddress1       = emp.EmpAddress1;
                employee.EmpAddress2       = emp.EmpAddress2;
                employee.EmpGender         = emp.EmpGender;
                employee.PositionPId       = emp.PositionPId;
                employee.DepartmentDprtId  = emp.DepartmentDprtId;
                employee.EmpProfilePicture = res;
                employee.ProjectPrId       = emp.ProjectId;

                int regitercode = _service.AddEmployee(employee);


                if (regitercode > 0)
                {
                    // if there register code send it bt email
                    Boolean SendCode = SendMail.SendloginCode(regitercode.ToString(), emp.EmpEmail, emp.EmpName);

                    return(Ok(emp));
                }
                else
                {
                    return(BadRequest("there error"));
                }
            }
            catch
            {
                return(BadRequest());
            }
        }
Exemple #5
0
        public IActionResult UpdateEmployee([FromForm] GetEmployee emp)
        {
            string res = "";

            if (emp.EmpProfilePicture != null)
            {
                // if there profile picture change it
                res = AddFiles.AddImage(emp.EmpProfilePicture, emp.EmpId);
            }
            Hash hash = new Hash();

            emp.EmpPassword = hash.HashPassword(emp.EmpPassword);

            Employee employee = new Employee();

            employee.EmpId             = emp.EmpId;
            employee.EmpEmail          = emp.EmpEmail;
            employee.EmpPassword       = emp.EmpPassword;
            employee.EmpName           = emp.EmpName;
            employee.EmpContact        = emp.EmpContact;
            employee.EmpAddress1       = emp.EmpAddress1;
            employee.EmpAddress2       = emp.EmpAddress2;
            employee.EmpGender         = emp.EmpGender;
            employee.PositionPId       = emp.PositionPId;
            employee.DepartmentDprtId  = emp.DepartmentDprtId;
            employee.EmpProfilePicture = res;
            employee.IsActive          = emp.IsActive;
            employee.StartDate         = emp.StartDate;
            employee.ProjectPrId       = emp.ProjectId;

            if (_service.UpdateEmployee(employee) == 1)
            {
                return(Ok("Changes success full!"));
            }
            if (_service.UpdateEmployee(employee) == 2)
            {
                return(BadRequest("Password not match, Try again."));
            }
            else
            {
                return(BadRequest("there are error"));
            }
        }
 private void SetInitialFocus()
 {
     AddFiles.Focus();
 }
Exemple #7
0
        protected void UploadFile(object sender, EventArgs e)
        {
            //Loaction where the file will be storred.
            string fLoc       = "User/Files/" + Context.User.Identity.GetUserName() + "/";
            string folderPath = Server.MapPath("~/User/Files/" + Context.User.Identity.GetUserName() + "/");

            //User who uploaded the file and has access to it.
            string ownerName = Context.User.Identity.GetUserName();

            //File original name.
            string originalName = FileUpload1.FileName;

            //Encoded name
            string encodedName = Path.GetRandomFileName();

            encodedName = encodedName.Replace(".", "");
            encodedName = encodedName + Path.GetExtension(FileUpload1.FileName);

            //Figures out what Category the File will belong to.
            int fCat = 0;

            if (Path.GetExtension(FileUpload1.FileName) == ".jpg" || Path.GetExtension(FileUpload1.FileName) == ".JPG" ||
                Path.GetExtension(FileUpload1.FileName) == ".png" || Path.GetExtension(FileUpload1.FileName) == ".PNG" ||
                Path.GetExtension(FileUpload1.FileName) == ".gif" || Path.GetExtension(FileUpload1.FileName) == ".GIF" ||
                Path.GetExtension(FileUpload1.FileName) == ".webp" || Path.GetExtension(FileUpload1.FileName) == ".WEBP")
            {
                fCat = 1;
            }

            else if (Path.GetExtension(FileUpload1.FileName) == ".mp4" || Path.GetExtension(FileUpload1.FileName) == ".MP4" ||
                     Path.GetExtension(FileUpload1.FileName) == ".wmv" || Path.GetExtension(FileUpload1.FileName) == ".WMV" ||
                     Path.GetExtension(FileUpload1.FileName) == ".mpg" || Path.GetExtension(FileUpload1.FileName) == ".MPG" ||
                     Path.GetExtension(FileUpload1.FileName) == ".avi" || Path.GetExtension(FileUpload1.FileName) == ".AVI" ||
                     Path.GetExtension(FileUpload1.FileName) == ".m4v" || Path.GetExtension(FileUpload1.FileName) == ".M4V")
            {
                fCat = 2;
            }

            else if (Path.GetExtension(FileUpload1.FileName) == ".txt" || Path.GetExtension(FileUpload1.FileName) == ".TXT" ||
                     Path.GetExtension(FileUpload1.FileName) == ".pdf" || Path.GetExtension(FileUpload1.FileName) == ".PDF" ||
                     Path.GetExtension(FileUpload1.FileName) == ".doc" || Path.GetExtension(FileUpload1.FileName) == ".DOC" ||
                     Path.GetExtension(FileUpload1.FileName) == ".docx" || Path.GetExtension(FileUpload1.FileName) == ".DOCX" ||
                     Path.GetExtension(FileUpload1.FileName) == ".tex" || Path.GetExtension(FileUpload1.FileName) == ".TEX" ||
                     Path.GetExtension(FileUpload1.FileName) == ".c" || Path.GetExtension(FileUpload1.FileName) == ".C" ||
                     Path.GetExtension(FileUpload1.FileName) == ".java" || Path.GetExtension(FileUpload1.FileName) == ".JAVA" ||
                     Path.GetExtension(FileUpload1.FileName) == ".cpp" || Path.GetExtension(FileUpload1.FileName) == ".CPP" ||
                     Path.GetExtension(FileUpload1.FileName) == ".cs" || Path.GetExtension(FileUpload1.FileName) == ".CS" ||
                     Path.GetExtension(FileUpload1.FileName) == ".class" || Path.GetExtension(FileUpload1.FileName) == ".CLASS")
            {
                fCat = 3;
            }
            else if (Path.GetExtension(FileUpload1.FileName) == ".zip" || Path.GetExtension(FileUpload1.FileName) == ".ZIP" ||
                     Path.GetExtension(FileUpload1.FileName) == ".rar" || Path.GetExtension(FileUpload1.FileName) == ".RAR" ||
                     Path.GetExtension(FileUpload1.FileName) == ".war" || Path.GetExtension(FileUpload1.FileName) == ".WAR" ||
                     Path.GetExtension(FileUpload1.FileName) == ".xar" || Path.GetExtension(FileUpload1.FileName) == ".XAR" ||
                     Path.GetExtension(FileUpload1.FileName) == ".pit" || Path.GetExtension(FileUpload1.FileName) == ".PIT" ||
                     Path.GetExtension(FileUpload1.FileName) == ".dar" || Path.GetExtension(FileUpload1.FileName) == ".DAR")
            {
                fCat = 4;
            }

            else if (Path.GetExtension(FileUpload1.FileName) == ".exe" || Path.GetExtension(FileUpload1.FileName) == ".EXE" ||
                     Path.GetExtension(FileUpload1.FileName) == ".jar" || Path.GetExtension(FileUpload1.FileName) == ".JAR" ||
                     Path.GetExtension(FileUpload1.FileName) == ".wsf" || Path.GetExtension(FileUpload1.FileName) == ".WSF" ||
                     Path.GetExtension(FileUpload1.FileName) == ".bin" || Path.GetExtension(FileUpload1.FileName) == ".BIN" ||
                     Path.GetExtension(FileUpload1.FileName) == ".py" || Path.GetExtension(FileUpload1.FileName) == ".PY")
            {
                fCat = 5;
            }

            else
            {
                fCat = 6;
            }

            //Check whether Directory (Folder) exists.
            if (!Directory.Exists(folderPath))
            {
                //If Directory (Folder) does not exists. Create it.
                Directory.CreateDirectory(folderPath);
            }

            //Save the File to the Directory (Folder).
            FileUpload1.SaveAs(folderPath + encodedName);

            //Display the success message.
            lblMessage.Text = Path.GetFileName(FileUpload1.FileName) + " has been uploaded.";

            //Add File info to the Database.
            AddFiles files = new AddFiles();

            files.AddFile(encodedName, originalName, AddFileDescription.Text, FileUpload1.PostedFile.ContentLength, fLoc, fCat, ownerName);
        }