public ActionResult Remove(string Source, string SourceId, string[] fileNames)
        {
            // The parameter of the Remove action must be called "fileNames"

            if (fileNames != null)
            {
                foreach (var fullName in fileNames)
                {
                    var fileName     = Path.GetFileName(fullName);
                    var physicalPath = Path.Combine(Server.MapPath("~/Files/uploadercash"), fileName);

                    // TODO: Verify user permissions

                    if (System.IO.File.Exists(physicalPath))
                    {
                        // The files are not actually removed in this demo
                        System.IO.File.Delete(physicalPath);
                        int SrcId            = int.Parse(SourceId);
                        CompanyDocsViews doc = _hrUnitOfWork.Repository <CompanyDocsViews>().SingleOrDefault(d => d.Source == "RenewRequest" && d.SourceId == SrcId && d.name == fileName);
                        _hrUnitOfWork.CompanyRepository.Remove(doc);
                        SaveChanges(Language);
                    }
                }
            }

            // Return an empty string to signify success
            return(Content(""));
        }
        public bool RemoveDocument(Guid Stream_Id, string RequiredDocTypeIDs, out string ErrorMessage, out int CurrentEmpStatus, out int OldEmpStatus)
        {
            OldEmpStatus     = 0;
            CurrentEmpStatus = 0;
            ErrorMessage     = string.Empty;
            try
            {
                CompanyDocsViews doc = hrUnitOfWork.CompanyDocsViewsRepository.GetByStreamID(Stream_Id);
                hrUnitOfWork.CompanyRepository.Remove(doc);

                List <int> RequiredDocTypeIDsList = GetListFromCommaSeperatedString(RequiredDocTypeIDs);
                CurrentEmpStatus = UpdatePersonStatus(doc.SourceId.Value, RequiredDocTypeIDsList, null, doc.TypeId, out OldEmpStatus);


                List <Error> errors = hrUnitOfWork.SaveChanges();
                if (errors.Count() > 0)
                {
                    ErrorMessage = errors.First().errors.First().message;
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                return(false);
            }
        }
Beispiel #3
0
        public List <Error> UploadOneFile(string Source, string SourceId)
        {
            List <Error> errors    = new List <Error>();
            var          imageData = _hrUnitOfWork.MissionRepository.GetBytes(int.Parse(SourceId));

            if (imageData != null)
            {
                return(errors);
            }
            var      file     = HttpContext.Request.Files[0];
            int      sid      = Convert.ToInt32(SourceId);
            var      stream   = ImageProcesses.ReadFully(file.InputStream);
            WebImage fullsize = null;
            WebImage thumbs   = null;

            fullsize = new WebImage(stream).Resize(1240, 1754);
            thumbs   = new WebImage(stream).Resize(124, 175);

            CompanyDocsViews doc = new CompanyDocsViews()
            {
                CompanyId   = CompanyId,
                name        = file.FileName,
                CreatedUser = UserName,
                Source      = Source,
                SourceId    = sid,
                file_stream = fullsize != null?fullsize.GetBytes() : stream,
                                  thumbs = thumbs != null?thumbs.GetBytes() : null
            };

            _hrUnitOfWork.CompanyRepository.Add(doc);
            errors = Save(Language);
            return(errors);
        }
Beispiel #4
0
        public ActionResult UpdateDocument(Model.ViewModel.CompanyDocViewModel doc)
        {
            if (ModelState.IsValid)
            {
                string           message = "OK,";
                CompanyDocsViews row     = new CompanyDocsViews();
                AutoMapper(new AutoMapperParm()
                {
                    Destination = row, Source = doc, ObjectName = "CompanyDocuments", Version = Convert.ToByte(Request.Form["Version"])
                });
                row.TypeId       = doc.DocType;
                row.ModifiedUser = doc.ModifiedUser;
                _hrUnitOfWork.CompanyRepository.Attach(row);
                _hrUnitOfWork.CompanyRepository.Entry(row).State = System.Data.Entity.EntityState.Modified;
                var errors = SaveChanges(Language);
                if (errors.Count() > 0)
                {
                    message = errors.First().errors.First().message;
                }
                else
                {
                    message += (new JavaScriptSerializer()).Serialize(doc);
                }

                return(Json(message));
            }
            return(Json(Models.Utils.ParseFormErrors(ModelState)));
        }
        private CompanyDocsViews Save_CompanyDocsViews(EmploymentPapersUploadVModel Model, string UserName, string Culture, int CompanyId, out int CurrentEmpStatus, out int OldEmpStatus)
        {
            OldEmpStatus     = 0;
            CurrentEmpStatus = 0;

            CompanyDocsViews doc = null;

            if (Model.Stream_Id != null)
            {
                doc = hrUnitOfWork.CompanyDocsViewsRepository.GetByStreamID(Model.Stream_Id.Value);
                doc.ModifiedUser = UserName;
                FillCommonData_CompanyDocsViews(ref doc, Model, Culture);
            }
            else
            {
                doc             = new CompanyDocsViews();
                doc.TypeId      = Model.TypeId;
                doc.CompanyId   = CompanyId;
                doc.CreatedUser = UserName;
                doc.Source      = Constants.Sources.People;
                doc.SourceId    = Model.EmpID;
                FillCommonData_CompanyDocsViews(ref doc, Model, Culture);
            }


            CurrentEmpStatus = UpdatePersonStatus(Model.EmpID, Model.RequiredDocTypeIDsList, Model.TypeId, null, out OldEmpStatus);
            return(doc);
        }
        public bool Save(EmploymentPapersUploadVModel Model, int CompanyId, string UserName, string Culture, out string ErrorMessage, out int CurrentEmpStatus, out int OldEmpStatus)
        {
            OldEmpStatus     = 0;
            CurrentEmpStatus = 0;
            ErrorMessage     = string.Empty;
            List <Error> errors = new List <Error>();

            try
            {
                CompanyDocsViews doc = Save_CompanyDocsViews(Model, UserName, Culture, CompanyId, out CurrentEmpStatus, out OldEmpStatus);
                SaveGrid_Section(Model, Culture, doc);
                errors = hrUnitOfWork.SaveChanges();

                if (errors.Count() > 0)
                {
                    ErrorMessage = errors.First().errors.First().message;
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
                return(false);
            }
            // }
        }
 public void Remove(CompanyDocsViews doc)
 {
     if (Context.Entry(doc).State == EntityState.Detached)
     {
         context.CompanyDocsView.Attach(doc);
     }
     context.CompanyDocsView.Remove(doc);
 }
Beispiel #8
0
        public JsonResult DeleteFile(Guid file)
        {
            CompanyDocsViews doc         = _hrUnitOfWork.Repository <CompanyDocsViews>().Single(d => d.stream_id == file);
            FilesHelper      filesHelper = new FilesHelper(DeleteURL, DeleteType, StorageRoot, UrlBase, tempPath, serverMapPath);

            _hrUnitOfWork.CompanyRepository.Remove(doc);
            SaveChanges(Language);
            filesHelper.DeleteFile(doc.name);
            return(Json("OK", JsonRequestBehavior.AllowGet));
        }
        public PartialViewResult UploadPaperPartial(int EmpID, int JobID, int Gender, int Nationality, int DocTypeID = 0, bool HasExpiryDate = false, Guid? Stream_Id = null,string RequiredDocTypeIDs="",bool IsEmpPaper=false)
        {
            int DocumentType = 0;
            bool IsAddNewOthers = true;
            List<SelectListItem> DocTypesList = new List<SelectListItem>();
            EmploymentPapers _EmploymentPapers = new EmploymentPapers(_hrUnitOfWork);

            if (DocTypeID == 0)
            {
                IsAddNewOthers = false;
                DocTypesList = _EmploymentPapers.GetPapers_Others(JobID, Gender, Nationality, CompanyId, User.Identity.GetCulture()).Select(d => new SelectListItem() { Value = d.Id.ToString(), Text = d.Name }).ToList();
            }
            else
            {
                DocumentType = _EmploymentPapers.GetDocumentType_ByDocTypeID(DocTypeID);
            }

            EmploymentPapersUploadVModel Model = new EmploymentPapersUploadVModel();
            Model.RequiredDocTypeIDs = RequiredDocTypeIDs;
            Model.ValidFileExtensions = "'.jpg','.jpeg','.bmp','.png','.gif','.pdf'";/*,'.doc','.docx','.xls','.xlsx'*/
            Model.DocumenType = DocumentType;
            Model.TypeId = DocTypeID;
            Model.DocTypesList = DocTypesList;
            Model.IsAddNewOthers = IsAddNewOthers;
            Model.HasExpiryDate = HasExpiryDate;
            Model.EmpID = EmpID;


            if (Stream_Id != null)
            {
                Model.IsUploaded = true;
                Model.Stream_Id = Stream_Id;

                CompanyDocsViews DocView = _EmploymentPapers.GetCompanyDocsViews_ByStreamID(Stream_Id.Value);
                if (DocView != null)
                {
                    Model.Keyword = DocView.Keyword;
                    Model.name = DocView.name;
                    Model.Description = DocView.Description;
                    Model.ExpireDate_string = DocView.ExpiryDate.ToMyDateString(User.Identity.GetCulture(), "dd/MM/yyyy");
                    Model.File_Type = DocView.file_type;
                    Model.IsEmpPaper = IsEmpPaper;
                }

            }
            //Model.OldModel_Serialized = new JavaScriptSerializer().Serialize(Model);
            FillBasicData(false, false,true, true);

            return PartialView("_UploadPaperPartial", Model);
        }
        private void FillCommonData_CompanyDocsViews(ref CompanyDocsViews doc, EmploymentPapersUploadVModel Model, string Culture)
        {
            //byte[] ImageStream = null;

            //if (Model.Images != null)
            //    ImageStream =  ImageProcesses.ReadFully(Model.Images.InputStream);

            doc.name        = Model.name;
            doc.Keyword     = Model.Keyword;
            doc.Description = Model.Description;
            doc.ExpiryDate  = (!string.IsNullOrEmpty(Model.ExpireDate_string)) ? (DateTime?)Model.ExpireDate_string.ToMyDateTime(Culture) : null;
            if (Model.ImageStream != null)
            {
                doc.file_stream = Model.ImageStream;
                doc.file_type   = Model.ContentType;
            }
        }
Beispiel #11
0
        public IHttpActionResult UploadFile(UploadedFileVm model)
        {
            var username = HttpContext.Current.User.Identity.Name;
            var i        = 0;

            if (model.Files.Count() > 0)
            {
                foreach (var item in model.Files)
                {
                    //FileStream fileStream = new FileStream(HttpContext.Current.Server.MapPath(serverMapPath + model.FileDetails[i]), FileMode.Create, FileAccess.ReadWrite);
                    //fileStream.Write(item, 0, item.Length);
                    //fileStream.Close();

                    CompanyDocsViews doc = new CompanyDocsViews()
                    {
                        CompanyId = model.CompanyId,
                        //name =  fileStream.Name,
                        name        = model.FileDetails[i],
                        CreatedUser = username,
                        Source      = model.Source,
                        SourceId    = model.TaskId,
                        file_stream = item
                    };

                    hrUnitOfWork.CompanyRepository.Add(doc);
                    i++;
                }
            }
            //else
            //{
            //    CompanyDocsViews doc = new CompanyDocsViews()
            //    {
            //        CompanyId = model.CompanyId,
            //        //name = model.FileDetails[i],
            //        name = string.Empty,
            //        CreatedUser = username,
            //        Source = model.Source,
            //        SourceId = model.TaskId
            //    };

            //    hrUnitOfWork.CompanyRepository.Add(doc);
            //}
            EmpTask oldTask = hrUnitOfWork.CheckListRepository.GetEmpTask(model.TaskId);

            //hrUnitOfWork.LeaveRepository.AddTrail(new AddTrailViewModel { ColumnName = "EndTime", ValueBefore = oldTask.EndTime.ToString(), ValueAfter = DateTime.Now.ToString(), ObjectName = "EmpTasksForm",  CompanyId = model.CompanyId, SourceId = oldTask.Id.ToString(), UserName = username });
            //hrUnitOfWork.LeaveRepository.AddTrail(new AddTrailViewModel { ColumnName = "Status", ValueBefore = oldTask.Status.ToString(), ValueAfter = "2", ObjectName = "EmpTasksForm",  CompanyId = model.CompanyId, SourceId = oldTask.Id.ToString(), UserName = username });

            if (oldTask.StartTime > DateTime.Now)
            {
                oldTask.StartTime = DateTime.Now;
            }

            oldTask.EndTime = DateTime.Now;
            oldTask.Status  = 2;
            TimeSpan duration = oldTask.EndTime.Value - oldTask.StartTime.Value;



            switch (oldTask.Unit)
            {
            case 0:    //Minutes
                oldTask.Duration = Convert.ToSByte(duration.Minutes);
                break;

            case 1:     //Hours
                oldTask.Duration = Convert.ToSByte(duration.Hours);
                break;

            case 2:     //Days
                oldTask.Duration = Convert.ToSByte(duration.Days);
                break;

            case 3:     //Weeks
                oldTask.Duration = Convert.ToSByte(duration.Days / 7);
                break;

            case 4:     //Months
                oldTask.Duration = Convert.ToSByte(duration.Days / 365.25 * 12);
                break;
            }
            //hrUnitOfWork.LeaveRepository.AddTrail(new AddTrailViewModel { ColumnName = "Status", ValueBefore = "", ValueAfter = oldTask.Duration.ToString(), ObjectName = "EmpTasksForm", Version = version, CompanyId = model.CompanyId, SourceId = oldTask.Id.ToString(), UserName = UserName });

            hrUnitOfWork.CheckListRepository.AssignNextTask(oldTask);
            oldTask.ModifiedTime = DateTime.Now;
            oldTask.ModifiedUser = username;

            var sc = SaveChanges(model.Language);

            return(Ok(sc));
        }
        private void SaveGrid_Section(EmploymentPapersUploadVModel Model, string Culture, CompanyDocsViews doc)
        {
            IList <CompanyDocAttr> oldCompDocAttr = null;

            if (Model.Stream_Id != null)
            {
                oldCompDocAttr = hrUnitOfWork.CompanyDocAttrRepository.GetDocAttrByStreamId(Model.Stream_Id.Value);
            }

            foreach (CompanyDocAttrViewModel UpdatedAttr in Model.BatchGridData_List)
            {
                //if (UpdatedAttr. !string.IsNullOrEmpty(UpdatedAttr.Value))
                //{
                if (!UpdatedAttr.Insert && oldCompDocAttr != null)
                {
                    var docAttr = oldCompDocAttr.Where(a => a.AttributeId == UpdatedAttr.Id).FirstOrDefault();
                    docAttr.Value   = Constants.CompanyDocAttr.getValue(UpdatedAttr, Culture);
                    docAttr.ValueId = UpdatedAttr.ValueId;
                }
                else
                {
                    var docAttr = new CompanyDocAttr();
                    docAttr.AttributeId = UpdatedAttr.Id;
                    docAttr.Value       = Constants.CompanyDocAttr.getValue(UpdatedAttr, Culture);
                    docAttr.ValueId     = UpdatedAttr.ValueId;
                    doc.CompanyDocAttrs.Add(docAttr);
                }
                //}
            }

            if (Model.Stream_Id == null)
            {
                hrUnitOfWork.CompanyDocsViewsRepository.Add(doc);
            }
        }
Beispiel #13
0
        public JsonResult Upload(string Source, string SourceId)
        {
            //if (Request.QueryString["Source"] != null && Request.QueryString["SourceId"] != null)
            //{
            //    Source = Request.QueryString["Source"]?.ToString();
            //    SourceId = Request.QueryString["SourceId"]?.ToString();
            //}
            var         resultList  = new List <ViewDataUploadFilesResult>();
            FilesHelper filesHelper = new FilesHelper(DeleteURL, DeleteType, StorageRoot, UrlBase, tempPath, serverMapPath);

            filesHelper.UploadAndShowResults(HttpContext, resultList);
            if (!resultList.Any())
            {
                return(Json("Error"));
            }


            JsonFiles files       = new JsonFiles(resultList);
            var       username    = UserName;
            var       names       = new List <string>();
            int       sid         = Convert.ToInt32(SourceId);
            var       CompanyDocs = _hrUnitOfWork.Repository <CompanyDocsViews>()
                                    .Where(d => d.Source == Source && d.SourceId == sid).Select(a => a.name).ToList();

            bool   Exist = false;
            string name  = files.files.FirstOrDefault().name;

            if (CompanyDocs.Contains(name))
            {
                string checkName = name;
                Exist = true;
                for (int i = 1; i <= CompanyDocs.Count; i++)
                {
                    checkName = string.Format("copy{0}_{1}", i, name);
                    if (!CompanyDocs.Contains(checkName))
                    {
                        name = checkName;
                        break;
                    }
                }
            }


            foreach (var item in files.files)
            {
                CompanyDocsViews doc = new CompanyDocsViews()
                {
                    CompanyId   = (Source == "Company" ? sid : CompanyId),
                    name        = Exist ? name : item.name,
                    CreatedUser = username,
                    Source      = Source,
                    SourceId    = sid,
                    file_stream = System.IO.File.ReadAllBytes(Server.MapPath(serverMapPath + item.name))
                };

                names.Add(doc.name);
                _hrUnitOfWork.CompanyRepository.Add(doc);
            }

            var errors = SaveChanges(Language);

            var model = _hrUnitOfWork.Repository <CompanyDocsViews>()
                        .Where(d => d.Source == Source && d.SourceId == sid && names.Contains(d.name))
                        .Select(d => new
            {
                sid  = d.stream_id,
                time = d.creation_time,
                name = d.name
            }).ToList();

            var result = from m in model
                         join file in files.files on m.name equals Exist ? name : file.name
                         select(new ViewDataUploadFilesResult
            {
                sid              = m.sid,
                name             = Exist ? name : file.name,
                deleteType       = file.deleteType,
                deleteUrl        = DeleteURL + m.sid,
                size             = file.size,
                thumbnailUrl     = file.thumbnailUrl,
                type             = file.type,
                url              = file.url,
                last_access_time = m.time.Value.ToString("dd/MM/yyyy hh:mm"),
                creation_time    = m.time.Value.ToString("dd/MM/yyyy hh:mm"),
                CreatedUser      = username,
                DocName          = m.name
            });

            return(Json(new JsonFiles(result.ToList()), JsonRequestBehavior.AllowGet));
        }
Beispiel #14
0
        public JsonResult UploadOneFile(string Source, string SourceId)
        {
            var file = HttpContext.Request.Files[0];

            if (file == null)
            {
                return(Json("No files found"));
            }

            int sid = Convert.ToInt32(SourceId);

            WebImage fullsize = null;
            WebImage thumbs   = null;

            byte[] stream = null;
            ImageProcesses.GetFull_ThumpImages(Source, file.InputStream, file.ContentType, out fullsize, out thumbs, out stream);
            //var stream = ReadFully(file.InputStream);
            //WebImage fullsize = null;
            //WebImage thumbs= null;

            //if (Source == "EmployeePic")
            //{
            //    fullsize = new WebImage(stream).Resize(180, 180);
            //    thumbs = new WebImage(stream).Resize(32, 32);
            //}
            //else if (Source == "CompanyLogo")
            //{
            //    fullsize = new WebImage(stream).Resize(396,130);
            //    thumbs = new WebImage(stream).Resize(80, 80);
            //}
            //else if (file.ContentType != "application/pdf")
            //{
            //    fullsize = new WebImage(stream).Resize(1240, 1754); //   1240, 1754    2480, 3508
            //    thumbs = new WebImage(stream).Resize(124, 175);
            //}
            //else if (file.ContentType == "application/pdf")
            //{
            //    // do nothing
            //}
            //else
            //{
            //    fullsize = new WebImage(stream).Resize(1240, 1754);
            //    thumbs = new WebImage(stream).Resize(80, 80);
            //}

            CompanyDocsViews doc = new CompanyDocsViews()
            {
                CompanyId   = (Source == "CompanyLogo" ? sid : CompanyId),
                name        = file.FileName,
                CreatedUser = UserName,
                Source      = Source,
                SourceId    = sid,
                file_stream = fullsize != null?fullsize.GetBytes() : stream,
                                  thumbs = thumbs != null?thumbs.GetBytes() : null
            };

            _hrUnitOfWork.CompanyRepository.Add(doc);

            var    errors = SaveChanges(Language);
            string error  = errors.Count > 0 ? errors.First().errors.First().message : "OK";

            return(Json(error));
        }
 public void Add(CompanyDocsViews doc)
 {
     context.CompanyDocsView.Add(doc);
 }
 public void Attach(CompanyDocsViews doc)
 {
     context.CompanyDocsView.Attach(doc);
 }
 public DbEntityEntry <CompanyDocsViews> Entry(CompanyDocsViews doc)
 {
     return(Context.Entry(doc));
 }