public Guid Put(Method obj) { Guid result = Guid.Empty; //try { SessionManager.DoWork(session => { if (obj.Id == Guid.Empty) { obj.Id = Guid.NewGuid(); if (obj.PlanKPIDetail.Id == Guid.Empty) { //Thêm vào plandetail mới (parent) PlanKPIDetail pld = new PlanKPIDetail(); pld.Id = Guid.NewGuid(); pld.PlanStaff = new PlanStaff() { Id = obj.PlanKPIDetail.PlanStaff.Id }; pld.TargetGroupDetail = obj.PlanKPIDetail.TargetGroupDetail; pld.StartTime = DateTime.Now; pld.EndTime = DateTime.Now; pld.CreateTime = DateTime.Now; obj.StartTime = obj.StartTime.ToLocalTime(); obj.EndTime = obj.EndTime.ToLocalTime(); obj.PlanKPIDetail = pld; pld.Methods = new List <Method>(); pld.Methods.Add(obj); session.Save(pld); //obj.PlanKPIDetail = pld; } else { obj.StartTime = obj.StartTime.ToLocalTime(); obj.EndTime = obj.EndTime.ToLocalTime(); session.Save(obj); } } else { obj.StartTime = obj.StartTime.ToLocalTime(); obj.EndTime = obj.EndTime.ToLocalTime(); session.SaveOrUpdate(obj); } result = obj.PlanKPIDetail.Id; //Update Cache //PlanKPIDetail temp = session.Query<PlanKPIDetail>().Where(p => p.Id == result).SingleOrDefault(); //ControllerHelpers.UpdatePlanDetailDic(temp, 1, session); }); //} //catch (Exception e) //{ // result = Guid.Empty; //} return(result); }
public Guid Put(FileAttachment obj) { Guid result = Guid.Empty; try { SessionManager.DoWork(session => { if (obj.Id == Guid.Empty) { obj.Id = Guid.NewGuid(); if (obj.PlanKPIDetail.Id == Guid.Empty) { //Thêm vào plandetail mới (parent) PlanKPIDetail pld = new PlanKPIDetail(); pld.Id = Guid.NewGuid(); pld.PlanStaff = new PlanStaff() { Id = obj.PlanKPIDetail.PlanStaff.Id }; pld.TargetGroupDetail = obj.PlanKPIDetail.TargetGroupDetail; pld.StartTime = DateTime.Now; pld.EndTime = DateTime.Now; pld.CreateTime = DateTime.Now; obj.CreationTime = DateTime.Now; obj.Name = obj.Name; obj.PlanKPIDetail = pld; pld.FileAttachments = new List <FileAttachment>(); pld.FileAttachments.Add(obj); session.Save(pld); //obj.PlanKPIDetail = pld; } else { obj.CreationTime = DateTime.Now; session.Save(obj); } } else { session.SaveOrUpdate(obj); } result = obj.PlanKPIDetail.Id; }); } catch (Exception e) { result = Guid.Empty; } return(result); }
public int CreateDocument(string document) { int result = 0; try { SessionManager.DoWork(session => { int year = DateTime.Now.Year; string pathVirtal = System.Configuration.ConfigurationManager.AppSettings["VanBanGuiDen"]; string pathPhysical = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["VanBanGuiDen"]); string virtualFilePath = ConfigurationManager.AppSettings["FilesPath"] + "/" + year; string filePath = HttpContext.Current.Server.MapPath(virtualFilePath); VanbanGui vbg = null; Guid id = Guid.NewGuid(); // Tạo đường dẫn chứa file văn bản string Virtalpath = pathPhysical + DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString() + "/" + DateTime.Now.Day.ToString() + "/"; //string path = HttpContext.Current.Server.MapPath(Virtalpath); if (!System.IO.Directory.Exists(Virtalpath)) { System.IO.Directory.CreateDirectory(Virtalpath); } // Lưu file xml vào thư mục XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(document); xdoc.Save(Virtalpath + id.ToString() + ".xml"); // Đọc file xml parse thành đối tượng VanBanGui XmlSerializer xmlser = new XmlSerializer(typeof(VanbanGui)); using (System.IO.Stream filetream = new FileStream(Virtalpath + id.ToString() + ".xml", FileMode.Open)) { filetream.Position = 0; vbg = (VanbanGui)xmlser.Deserialize(filetream); } // Insert văn bản vào database if (vbg != null) { foreach (To to in vbg.Messageheader.To) { string did = to.OrganId; StaffApiController sc = new StaffApiController(); //Guid leaderId = new Guid(sc.GetDepartmentLeaderId(new Guid(did))); Guid toDepartmentId = session.Query <EOfficeHRMDepartment>().SingleOrDefault(h => h.EOfficeDepartmentId.ToString() == did).DepartmentId; PlanStaff plst = session.Query <PlanStaff>().SingleOrDefault(p => p.Department.Id == toDepartmentId && p.PlanKPI.StartTime.Month == DateTime.Now.Month && p.PlanKPI.StartTime.Year == DateTime.Now.Year); PlanKPIDetail planDetail = new PlanKPIDetail(); planDetail.TargetDetail = vbg.Subject; planDetail.Id = Guid.NewGuid(); planDetail.Name = vbg.Messageheader.From.Name; planDetail.PlanStaff = plst; planDetail.CreateTime = DateTime.Now; planDetail.IsAddition = true; planDetail.IsFromEoffice = true; planDetail.StartTime = plst.PlanKPI.StartTime; planDetail.EndTime = plst.PlanKPI.EndTime; Method method = new Method(); method.StartTime = plst.PlanKPI.StartTime; method.EndTime = plst.PlanKPI.EndTime; planDetail.Methods = new List <Method>(); planDetail.Methods.Add(method); session.Save(planDetail); foreach (Attachment item in vbg.Document.Attach) { FileAttachment fa = new FileAttachment(); fa.Id = planDetail.Id; fa.Name = item.Name; fa.Extension = System.IO.Path.GetExtension(item.Name); string PathFileResource = filePath + "/" + fa.Id.ToString() + fa.Extension; File.WriteAllBytes(PathFileResource, item.Value); if (!System.IO.File.Exists(PathFileResource)) { System.IO.File.WriteAllBytes(PathFileResource, item.Value); } fa.Path = virtualFilePath + "/" + fa.Id.ToString() + fa.Extension; fa.PlanKPIDetail = new PlanKPIDetail() { Id = planDetail.Id }; fa.CreationTime = DateTime.Now; session.Save(fa); } } } else { //Không đọc dc xml result = -1; } }); } catch { result = -2; // lỗi khác } return(result); }
public IEnumerable <DepartmentHierarchyDTO> GetMainDepartmentListHierarchy(Guid planDetailId) { List <DepartmentHierarchyDTO> result = new List <DepartmentHierarchyDTO>(); SessionManager.DoWork(session => { List <Guid> subDepartmentIds = new List <Guid>(); PlanKPIDetail pld = session.Query <PlanKPIDetail>().SingleOrDefault(p => p.Id == planDetailId); if (pld != null) { subDepartmentIds = pld.SubDepartments.Select(d => d.Id).ToList(); } Guid spkt = new Guid("E054A602-E077-444C-B843-E856D643CA7F"); List <Department> deptList = new List <Department>(); deptList = session.Query <Department>().Where(d => d.ParentDepartment.Id == spkt && d.GCRecord == null && d.IsDisable == false).OrderBy(d => d.Name).ToList(); DepartmentHierarchyDTO phong = new DepartmentHierarchyDTO(); phong.Id = new Guid("00000000-0000-0000-0000-000000000001"); phong.Name = "Phòng ban"; result.Add(phong); DepartmentHierarchyDTO khoa = new DepartmentHierarchyDTO(); khoa.Id = new Guid("00000000-0000-0000-0000-000000000002"); khoa.Name = "Khoa/Viện/Trung tâm"; result.Add(khoa); DepartmentHierarchyDTO khac = new DepartmentHierarchyDTO(); khac.Id = new Guid("00000000-0000-0000-0000-000000000003"); khac.Name = "Khác"; result.Add(khac); List <DepartmentDTO> listDept = new List <DepartmentDTO>(); foreach (Department pl in deptList) { DepartmentDTO pd = pl.Map <DepartmentDTO>(); switch (pd.DepartmentType) { case 1: { pd.ParentId = new Guid("00000000-0000-0000-0000-000000000001"); } break; case 4: { pd.ParentId = new Guid("00000000-0000-0000-0000-000000000002"); } break; default: { pd.ParentId = new Guid("00000000-0000-0000-0000-000000000003"); } break; } listDept.Add(pd); } foreach (DepartmentHierarchyDTO dh in result) { dh.items = new List <DepartmentDTO>(); foreach (DepartmentDTO dt in listDept) { if (dt.ParentId == dh.Id) { if (subDepartmentIds.Contains(dt.Id)) { dt.@checked = true; } dh.items.Add(dt); } } } }); return(result); }
// GET: FileUpload public ActionResult SavePlanDetailFile(IEnumerable <HttpPostedFileBase> files, Guid id, Guid planStaffId, Guid targetGroupDetailId) { // The Name of the Upload component is "files" SessionManager.DoWork(session => { if (files != null) { int year = DateTime.Now.Year; string filePath = ConfigurationManager.AppSettings["FilesPath"] + "/" + year; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(Server.MapPath(filePath)); } foreach (var file in files) { FileAttachment pf = new FileAttachment(); pf.Id = Guid.NewGuid(); pf.Name = Path.GetFileNameWithoutExtension(file.FileName); pf.Extension = Path.GetExtension(file.FileName); // Some browsers send file names with full path. This needs to be stripped. var fileName = Path.GetFileName(file.FileName); var actualFileName = string.Format("{0}{1}", pf.Id, Path.GetExtension(file.FileName)); var physicalPath = Path.Combine(Server.MapPath(filePath), actualFileName); pf.Path = filePath + "/" + actualFileName; //Save file xuống server file.SaveAs(physicalPath); if (id == Guid.Empty) { //Thêm vào plandetail mới (parent) PlanKPIDetail pld = new PlanKPIDetail(); pld.Id = Guid.NewGuid(); pld.PlanStaff = new PlanStaff() { Id = planStaffId }; pld.TargetGroupDetail = new TargetGroupDetail() { Id = targetGroupDetailId }; pld.StartTime = DateTime.Now; pld.EndTime = DateTime.Now; pld.CreateTime = DateTime.Now; pf.CreationTime = DateTime.Now; pf.Name = pf.Name; pf.PlanKPIDetail = pld; pld.FileAttachments = new List <FileAttachment>(); pld.FileAttachments.Add(pf); session.Save(pld); //obj.PlanKPIDetail = pld; } else { pf.PlanKPIDetail = new PlanKPIDetail() { Id = id }; pf.CreationTime = DateTime.Now; session.Save(pf); } } } }); // Return an empty string to signify success return(Content("")); }