//勾選通過 public JsonResult getPassString(string d) { string[] ids = d.Split('\\', '"', '[', ',', ']'); List <int> list = new List <int>(); foreach (var item in ids) { if (item != "") { list.Add(int.Parse(item)); } } foreach (var i in list) { TLeaveApplication leave = DB.TLeaveApplications.FirstOrDefault(c => c.CApplyNumber == i); if (leave.CCheckStatus == 1) { if (leave != null) { leave.CCheckStatus = 2; DB.SaveChanges(); } } } return(Json(d)); }
public IActionResult Edit(CInterviewEditViewModel I) { if (I != null) { TInterView table = myHR.TInterViews.Where(n => n.CInterVieweeId == I.CInterVieweeId).FirstOrDefault(); if (table != null) { table.CInterVieweeName = I.CInterVieweeName; table.CInterViewStatusId = int.Parse(I.CStatus); myHR.SaveChanges(); } } // 如果狀態為待報到 跳至新增帳號頁面 if (int.Parse(I.CStatus) == 3) { var interviewer = myHR.TInterViews.Where(n => n.CInterVieweeId == I.CInterVieweeId).FirstOrDefault(); //HttpContext.Session.SetObject<TInterView>(CDictionary.Register_User, interviewer); TempData.Put("Register", interviewer); AddNoti(1, "新人報到通知", $"貴部門 {interviewer.CInterVieweeName} 確認報到,已發送報到通知。"); return(RedirectToAction("register", "employee")); } TempData["Id"] = I.CInterVieweeId; return(RedirectToAction("List")); }
public IActionResult Create(CPropertyViewModel pmodel) { if (ModelState.IsValid == false) { ViewBag.Departments = db.TUserDepartments.ToList(); ViewBag.check = db.TLostAndFoundCheckStatuses.ToList(); ViewBag.subject = db.TLostAndFoundSubjects.ToList(); ViewBag.category = db.TLostAndFoundCategories.ToList(); ViewBag.cphone = db.TUsers.ToList(); return(View(pmodel)); } if (pmodel.image != null) { pmodel.CPropertyPhoto = uploadImage(pmodel.image); } db.TLostAndFounds.Add(new TLostAndFound { CDeparmentId = pmodel.CDeparmentId, CEmployeeId = pmodel.CEmployeeId, CLostAndFoundDate = DateTime.UtcNow.AddHours(8), CLostAndFoundSpace = pmodel.CLostAndFoundSpace, CPhone = pmodel.CPhone, CProperty = pmodel.CProperty, CPropertyCategoryId = pmodel.CPropertyCategoryId, CPropertyPhoto = pmodel.CPropertyPhoto, CPropertySubjectId = pmodel.CPropertySubjectId, CPropertyCheckStatusId = pmodel.CPropertyCheckStatusId, CtPropertyDescription = pmodel.CtPropertyDescription }); db.SaveChanges(); return(RedirectToAction("List")); }
public IActionResult RepairCreate(CReairViewModel cReair) { db.TRepairs.Add(cReair.repair); db.SaveChanges(); return(RedirectToAction("RepairList")); }
public IActionResult pUdate(int?id) { if (id != null) { TLostAndFound tlaf = db.TLostAndFounds.FirstOrDefault(e => e.CPropertyId == id); if (tlaf != null) { tlaf.CPropertyCheckStatusId = 2; db.SaveChanges(); } } return(RedirectToAction("List")); }
//勾選退件 public JsonResult getFailString(string d) { string[] ids = d.Split('\\', '"', '[', ',', ']'); List <int> list = new List <int>(); foreach (var item in ids) { if (item != "") { list.Add(int.Parse(item)); } } foreach (var i in list) { dbMyCompanyContext db = new dbMyCompanyContext(); TTravelExpenseApplication travel = db.TTravelExpenseApplications.FirstOrDefault(c => c.CApplyNumber == i); if (travel != null) { if (travel.CCheckStatus == 1) { travel.CCheckStatus = 3; db.SaveChanges(); } } } return(Json(d)); }
public void AddNotification(List <TNotification> data) { foreach (var item in data) { db.TNotifications.Add(item); } db.SaveChanges(); }
public async Task <IActionResult> ProfileEdit(TUser user, TUserViewModel user_vm, List <IFormFile> CPhoto) { user = HttpContext.Session.GetObject <TUser>(CDictionary.Current_User);//取一個在session中的TUser物件(可抓到id) foreach (var item in CPhoto) { if (item.Length > 0) { using (var stream = new MemoryStream()) { await item.CopyToAsync(stream); user.CPhoto = stream.ToArray(); } } if (user != null) { db.Update(user); db.SaveChanges(); } } //return View(); if (user_vm != null) { TUser u = db.TUsers.FirstOrDefault(p => p.CEmployeeId == user_vm.CEmployeeId); if (u != null) { u.CEmployeeEnglishName = user_vm.CEmployeeEnglishName; u.CPassWord = user_vm.CPassWord; u.CGender = user_vm.CGender; u.CEmail = user_vm.CEmail; u.CAddress = user_vm.CAddress; u.CBirthday = (user_vm.CBirthday != null) ? (DateTime)user_vm.CBirthday : null; u.CPhone = user_vm.CPhone; u.CEmergencyPerson = user_vm.CEmergencyPerson; u.CEmergencyContact = user_vm.CEmergencyContact; u.CAccountEnable = user_vm.CAccountEnable; db.SaveChanges(); } } return(RedirectToAction("Profile")); }
public JsonResult check([FromBody] CPasswordTest p) { //CLoginViewModel p = new CLoginViewModel(); string Data = ""; if (p.txtaccount1 != null && p.txtpassword1 != null) { using (dbMyCompanyContext db = new dbMyCompanyContext()) { var user = db.TUsers.Where(a => a.CEmployeeEnglishName == p.txtaccount1).FirstOrDefault(); if (user != null) { if (user.CPassWord != p.txtpassword1) { Data = "密碼錯誤"; } else { user.CAccountEnable = 1; db.SaveChanges(); // interView 修改成已報到 var id = db.TUsers.Where(n => n.CEmployeeEnglishName == p.txtaccount1).Select(n => n.CEmployeeId).FirstOrDefault(); var interview = db.TInterViews.Where(n => n.CInterViewerEmployeeId == id).FirstOrDefault(); if (interview != null) { interview.CInterViewStatusId = 6; } db.SaveChanges(); Data = $"報到成功,您的員工帳號為\"{id}\",請至登入頁面進入本系統。"; } } else { Data = "帳號錯誤"; } } } return(Json(Data)); }
public IActionResult LeaveCreate(TLeaveApplicationCreateViewModel T) { var errors = ModelState.Values.SelectMany(v => v.Errors); if (ModelState.IsValid) //[Reurired]在CORE可以成功使用 { MyHr.TLeaveApplications.Add(T.Leave); //await MyHr.SaveChangesAsync(); MyHr.SaveChanges(); return(RedirectToAction("LeaveList")); } else { //ModelState.AddModelError("CReason", "幹這個錯誤訊息跳出來,就算輸入資料了,也不會驗證過,不懂存在的意義"); List <TLeave> listLeave = GetLeaveList(); //★我怎麼這抹巧!!!★ ViewBag.LeaveCate = listLeave; return(View()); } //return RedirectToAction("LeaveCreate"); }
public IActionResult Create(CTravelViewModel model) { if (ModelState.IsValid == false) { ViewBag.Departments = db.TUserDepartments.ToList(); ViewBag.Status = db.TCheckStatuses.ToList(); return(View(model)); } db.TTravelExpenseApplications.Add(new TTravelExpenseApplication { CAmont = model.CAmont, CApplyDate = DateTime.UtcNow.AddHours(8), CCheckStatus = model.CCheckStatus, CDepartmentId = model.CDepartmentId, CEmployeeId = model.CEmployeeId, CReason = model.CReason, CTravelEndTime = model.CTravelEndTime, CTravelStartTime = model.CTravelStartTime }); db.SaveChanges(); return(RedirectToAction("List")); }
// 新增通知 public void AddNoti(int toUserId, string notiHeader, string notiBody) { var user = HttpContext.Session.GetObject <TUser>(CDictionary.Current_User); TNotification noti = new TNotification(); noti.FromUserId = user.CEmployeeId; noti.ToUserId = toUserId; noti.NotiHeader = notiHeader; noti.NotiBody = notiBody; noti.IsRead = false; noti.Url = "123"; noti.CreatedDate = DateTime.Now; myHR.Add(noti); myHR.SaveChanges(); }
public IActionResult fail(int?id) { if (id != null) { dbMyCompanyContext db = new dbMyCompanyContext(); TTravelExpenseApplication travel = db.TTravelExpenseApplications.FirstOrDefault(t => t.CApplyNumber == id); if (travel != null) { if (travel.CCheckStatus == 1) { travel.CCheckStatus = 3; db.SaveChanges(); } } } return(RedirectToAction("List")); }
public IActionResult fail(int?id) { if (id != null) { dbMyCompanyContext db = new dbMyCompanyContext(); TLeaveApplication leave = db.TLeaveApplications.FirstOrDefault(l => l.CApplyNumber == id); if (leave != null) { if (leave.CCheckStatus == 1) { leave.CCheckStatus = 3; db.SaveChanges(); } } } return(RedirectToAction("List")); }
public JsonResult DeleteEvent(int eventID) { var status = false; using (dbMyCompanyContext db = new dbMyCompanyContext()) { var v = db.TEvents.Where(a => a.EventId == eventID).FirstOrDefault(); if (v != null) { db.TEvents.Remove(v); db.SaveChanges(); status = true; } } var Data = status; //return new JsonResult { Data = new { status = status } }; return(new JsonResult(Data)); }
public JsonResult SaveEvent(CalendarViewModel e) { var status = false; using (dbMyCompanyContext db = new dbMyCompanyContext()) { int userId = int.Parse(HttpContext.Session.GetString(CDictionary.CURRENT_LOGINED_USERID)); ViewData["userId"] = userId; if (e.EventId > 0) { //Update the event var v = db.TEvents.Where(a => a.EventId == e.EventId).FirstOrDefault(); if (v != null) { v.EmployeeId = userId; v.Subject = e.Subject; v.Start = e.Start; v.End = e.End; v.Description = e.Description; v.IsFullDay = e.IsFullDay; v.ThemeColor = e.ThemeColor; } } else { db.TEvents.Add(e.tevents); } db.SaveChanges(); status = true; } var Data = status; //return new JsonResult { Data = new { status = status } }; return(new JsonResult(Data)); }
public IActionResult getClockString_on(int id, DateTime date)//上班 { try { int userId = int.Parse(HttpContext.Session.GetString(CDictionary.CURRENT_LOGINED_USERID)); TAbsence td = db.TAbsences.FirstOrDefault(z => z.CDate.Value.Date == DateTime.Today && z.CEmployeeId == id && z.COn.HasValue); //尋找該員工今天的打卡紀錄 if (td == null) //今天未打卡 { if (now <= Con) //9:00前 { TAbsence b = new TAbsence() { CEmployeeId = id, CDate = date, COn = TimeSpan.Parse(now.ToString("HH:mm:ss")), CStatus = "正常", }; db.TAbsences.Add(b); } else if (now > Con && now < Late)//9:00-9:59 { TAbsence b = new TAbsence() { CEmployeeId = id, CDate = date, COn = TimeSpan.Parse(now.ToString("HH:mm:ss")), CStatus = "遲到", }; db.TAbsences.Add(b); } else if (now >= Late)//10:00(含)之後 { TAbsence b = new TAbsence() { CEmployeeId = id, CDate = date, COn = TimeSpan.Parse(now.ToString("HH:mm:ss")), CStatus = "異常", }; db.TAbsences.Add(b); } db.SaveChanges(); } DateTime dtMonday = DateTime.Now.AddDays(1 - Convert.ToInt16(DateTime.Now.DayOfWeek)); //當週週一 DateTime dtSunday = dtMonday.AddDays(6); //當週週日 var table = db.TAbsences .Where(a => a.CEmployeeId == userId && a.CDate >= dtMonday && a.CDate <= dtSunday) .OrderByDescending(a => a.CDate).ToList(); List <CAbsenceViewModel> list = new List <CAbsenceViewModel>(); foreach (var item in table) { CAbsenceViewModel avm = new CAbsenceViewModel() { CApplyNumber = item.CApplyNumber, CDate = item.CDate, COn = item.COn, COff = item.COff, CStatus = item.CStatus }; list.Add(avm); } getCountNum(); return(PartialView("ClockOnAndOff", list)); } catch (Exception) { throw; } }
public IActionResult register(TUserViewModel _user) { ViewBag.CDepartmentId = db.TUserDepartments.ToList(); ViewBag.CJobTitleId = db.TUserJobTitles.ToList(); //新增員工 db.TUsers.Add(_user.tuserVM); db.SaveChanges(); //給面試要報到的人employeeId int id = db.TUsers.Where(n => n.CEmployeeName == _user.CEmployeeName).Select(n => n.CEmployeeId).FirstOrDefault(); TInterView table = db.TInterViews.Where(n => n.CEmployeeEnglishName == _user.CEmployeeEnglishName).FirstOrDefault(); if (table != null) { table.CInterViewerEmployeeId = id; db.SaveChanges(); } //開始寄信 int userid = db.TUsers.OrderByDescending(n => n.CEmployeeId).Select(c => c.CEmployeeId).FirstOrDefault(); //撈取新註冊的員工ID string name = db.TUsers.Where(n => n.CEmployeeId == userid).Select(c => c.CEmployeeName).FirstOrDefault(); //撈取新註冊的員工NAME string email = db.TUsers.Where(n => n.CEmployeeId == userid).Select(c => c.CEmail).FirstOrDefault(); //撈取新註冊的員工EMAIL string password = db.TUsers.Where(n => n.CEmployeeId == userid).Select(c => c.CPassWord).FirstOrDefault(); //撈取新註冊的員工PASSWORD string english = db.TUsers.Where(n => n.CEmployeeId == userid).Select(c => c.CEmployeeEnglishName).FirstOrDefault(); //撈取新註冊的員工PASSWORD try { System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); msg.To.Add(email); msg.From = new MailAddress("*****@*****.**", "HELLOWORK公司", System.Text.Encoding.UTF8); /* 上面3個參數分別是發件人地址,發件人姓名,編碼*/ msg.Subject = "錄取報到通知"; //郵件標題 msg.SubjectEncoding = System.Text.Encoding.UTF8; //郵件標題編碼 //郵件內容 msg.Body = name + " 您好," + Environment.NewLine; msg.Body += "您已錄取本公司,請至公司官網報到啟用帳號。" + Environment.NewLine; msg.Body += "登入帳號:" + userid + Environment.NewLine; msg.Body += "英文姓名:" + english + Environment.NewLine; msg.Body += "密碼:" + password + Environment.NewLine; //郵件內容 msg.BodyEncoding = System.Text.Encoding.UTF8; //郵件內容編碼 /* msg.Attachments.Add(new Attachment(@"D:\test2.docx")); */ //附件 msg.IsBodyHtml = true; //是否是HTML郵件 //msg.Priority = MailPriority.High;//郵件優先級 SmtpClient client = new SmtpClient(); client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "izougqdehrjrufoh"); //這裡要填正確的帳號跟密碼 client.Host = "smtp.gmail.com"; //設定smtp Server client.Port = 25; //設定Port client.EnableSsl = true; //gmail預設開啟驗證 client.Send(msg); //寄出信件 client.Dispose(); msg.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(RedirectToAction("employeeList")); }