public ActionResult DeleteConfirmed(int id) { ms_employee_detail ms_employee_detail = db.ms_employee_detail.Find(id); db.ms_employee_detail.Remove(ms_employee_detail); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: employee_detail/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ms_employee_detail ms_employee_detail = db.ms_employee_detail.Find(id); if (ms_employee_detail == null) { return(HttpNotFound()); } return(View(ms_employee_detail)); }
public ActionResult Edit([Bind(Include = "emp_det_id,employee_id,company_id,department_id,job_level_id,user_type_id,fl_approver,range_id,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] ms_employee_detail ms_employee_detail) { if (ModelState.IsValid) { db.Entry(ms_employee_detail).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.range_id = new SelectList(db.ms_approval_range, "range_id", "range_type", ms_employee_detail.range_id); ViewBag.company_id = new SelectList(db.ms_asmin_company, "company_id", "company_code", ms_employee_detail.company_id); ViewBag.department_id = new SelectList(db.ms_department, "department_id", "department_code", ms_employee_detail.department_id); ViewBag.employee_id = new SelectList(db.ms_employee, "employee_id", "employee_nik", ms_employee_detail.employee_id); ViewBag.job_level_id = new SelectList(db.ms_job_level, "job_level_id", "job_level_code", ms_employee_detail.job_level_id); ViewBag.user_type_id = new SelectList(db.ms_user_type, "user_type_id", "user_type_code", ms_employee_detail.user_type_id); return(View(ms_employee_detail)); }
// GET: employee_detail/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ms_employee_detail ms_employee_detail = db.ms_employee_detail.Find(id); if (ms_employee_detail == null) { return(HttpNotFound()); } ViewBag.range_id = new SelectList(db.ms_approval_range, "range_id", "range_type", ms_employee_detail.range_id); ViewBag.company_id = new SelectList(db.ms_asmin_company, "company_id", "company_code", ms_employee_detail.company_id); ViewBag.department_id = new SelectList(db.ms_department, "department_id", "department_code", ms_employee_detail.department_id); ViewBag.employee_id = new SelectList(db.ms_employee, "employee_id", "employee_nik", ms_employee_detail.employee_id); ViewBag.job_level_id = new SelectList(db.ms_job_level, "job_level_id", "job_level_code", ms_employee_detail.job_level_id); ViewBag.user_type_id = new SelectList(db.ms_user_type, "user_type_id", "user_type_code", ms_employee_detail.user_type_id); return(View(ms_employee_detail)); }
public ActionResult Setup(employee_setupViewModel emp_setup) { if (ModelState.IsValid) { using (var transaction = db.Database.BeginTransaction()) { emp_setup.ms_employee = db.ms_employee.Find(emp_setup.employee_id); try { //List<ms_employee_detail> emp_detils = (from t in db.ms_employee_detail // where t.employee_id == emp_setup.employee_id // select t).ToList<ms_employee_detail>(); //if (emp_detils.Count > 0) //{ // foreach (var itm in emp_detils) // { // db.ms_employee_detail.Remove(itm); // } //} //emp_setup.company_list = (from t in db.ms_asmin_company where (t.fl_active == true && t.deleted_date == null) select t).ToList(); if (emp_setup.selected_company_id.Length > 0) { //karena di hide if (emp_setup.selected_range_id == null) { emp_setup.selected_range_id = new int[emp_setup.selected_company_id.Length]; } int i_loop = 0; //foreach (var company_loop in emp_setup.company_list) foreach (var _company_id in emp_setup.selected_company_id) { ms_employee_detail emp_detail = (from t in db.ms_employee_detail where (t.employee_id == emp_setup.employee_id && t.company_id == _company_id) select t).FirstOrDefault <ms_employee_detail>(); emp_setup.selected_range_id[i_loop] = 0; //di hide if (emp_detail != null) //update { emp_detail.asset_reg_location_id = (emp_setup.selected_register_id[i_loop] > 0) ? emp_setup.selected_register_id[i_loop] : (int?)null; emp_detail.location_id = (emp_setup.selected_register_id[i_loop] > 0) ? emp_setup.selected_register_id[i_loop] : (int?)null; emp_detail.department_id = (emp_setup.selected_department_id[i_loop] > 0) ? emp_setup.selected_department_id[i_loop] : (int?)null; emp_detail.job_level_id = (emp_setup.selected_job_level_id[i_loop] > 0) ? emp_setup.selected_job_level_id[i_loop] : (int?)null; //emp_detail.user_type_id = (emp_setup.selected_user_type_id[i_loop] > 0) ? emp_setup.selected_user_type_id[i_loop] : (int?)null; emp_detail.range_id = (emp_setup.selected_range_id[i_loop] > 0) ? (int)emp_setup.selected_range_id[i_loop] : (int?)null; emp_detail.fl_approver = (emp_setup.selected_range_id[i_loop] > 0); emp_detail.fl_active = true; emp_detail.created_by = UserProfile.UserId; emp_detail.created_date = DateTime.Now; emp_detail.updated_by = UserProfile.UserId; emp_detail.updated_date = DateTime.Now; emp_detail.deleted_by = null; emp_detail.deleted_date = null; emp_detail.org_id = UserProfile.OrgId; db.Entry(emp_detail).State = EntityState.Modified; } else //insert { db.ms_employee_detail.Add(new ms_employee_detail { employee_id = emp_setup.employee_id, company_id = _company_id, asset_reg_location_id = (emp_setup.selected_register_id[i_loop] > 0) ? emp_setup.selected_register_id[i_loop] : (int?)null, location_id = (emp_setup.selected_location_id[i_loop] > 0) ? emp_setup.selected_location_id[i_loop] : (int?)null, department_id = (emp_setup.selected_department_id[i_loop] > 0) ? emp_setup.selected_department_id[i_loop] : (int?)null, job_level_id = (emp_setup.selected_job_level_id[i_loop] > 0) ? emp_setup.selected_job_level_id[i_loop] : (int?)null, //user_type_id = (emp_setup.selected_user_type_id[i_loop] > 0) ? emp_setup.selected_user_type_id[i_loop] : (int?)null, range_id = (emp_setup.selected_range_id[i_loop] > 0) ? (int)emp_setup.selected_range_id[i_loop] : (int?)null, fl_approver = (emp_setup.selected_range_id[i_loop] > 0), fl_active = true, created_by = UserProfile.UserId, created_date = DateTime.Now, updated_by = UserProfile.UserId, updated_date = DateTime.Now, deleted_by = null, deleted_date = null, org_id = UserProfile.OrgId }); } i_loop += 1; } } db.SaveChanges(); transaction.Commit(); ViewBag.ResultMessage = "Record inserted into table successfully."; return(RedirectToAction("Index")); } catch (Exception ex) { transaction.Rollback(); ViewBag.ResultMessage = string.Format("Error occured, records rolledback. {0}", ex.Message); } } } return(View(emp_setup)); }
/* * employee setup */ public ActionResult Setup(int?id) { if (id == null) { return(RedirectToAction("Index")); //return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } ms_employee emp_db = db.ms_employee.Single(a => a.employee_id == id); if (emp_db == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } employee_setupViewModel model = new employee_setupViewModel() { employee_id = emp_db.employee_id, ms_employee = emp_db }; List <SelectListItem> first = new List <SelectListItem> { new SelectListItem { Text = "- [Not Set] -", Value = "0", Selected = true } }; model.company_list = (from t in db.ms_asmin_company where (t.fl_active == true && t.deleted_date == null) select t).ToList(); model.sli_register_list = (from t in db.ms_asset_register_location where (t.fl_active == true && t.deleted_date == null) select new SelectListItem { Text = t.asset_reg_location_name, Value = t.asset_reg_location_id.ToString() } ).ToList <SelectListItem>().Union(first); model.sli_location_list = (from t in db.ms_asset_location where (t.fl_active == true && t.deleted_date == null) //&& t.asset_reg_location_id == model.selected_register_id[0] select new SelectListItem { Text = t.location_name, Value = t.location_id.ToString() } ).ToList <SelectListItem>().Union(first); model.sli_department_list = (from t in db.ms_department where (t.fl_active == true && t.deleted_date == null) //from d in db.ms_employee_detail //where (d.employee_id == emp_db.employee_id && t.department_id == d.department_id) select new SelectListItem { Text = t.department_name, Value = t.department_id.ToString() //Selected = (d.employee_id>0) } ).ToList <SelectListItem>().Union(first); model.sli_job_level_list = (from t in db.ms_job_level where (t.fl_active == true && t.deleted_date == null) select new SelectListItem { Text = t.job_level_name, Value = t.job_level_id.ToString() } ).ToList <SelectListItem>().Union(first); model.sli_user_type_list = (from t in db.ms_user_type where (t.fl_active == true && t.deleted_date == null) select new SelectListItem { Text = t.user_type_name, Value = t.user_type_id.ToString() } ).ToList <SelectListItem>().Union(first); model.sli_range_list = (from t in db.ms_approval_range where (t.fl_active == true && t.deleted_date == null) select new SelectListItem { Text = t.range_code, Value = t.range_id.ToString() } ).ToList <SelectListItem>().Union(first); int i_pos = 0; int i_max = model.company_list.Count; foreach (ms_asmin_company company in model.company_list) { employee_detailViewModel _item = new employee_detailViewModel() { employee_id = emp_db.employee_id, ms_asmin_company = company, sli_register_list = model.sli_register_list, sli_location_list = model.sli_location_list, sli_department_list = model.sli_department_list, sli_job_level_list = model.sli_job_level_list, sli_user_type_list = model.sli_user_type_list, sli_range_list = model.sli_range_list }; ms_employee_detail dtl_db = (from d in db.ms_employee_detail where (d.employee_id == emp_db.employee_id && d.company_id == company.company_id) select d).FirstOrDefault <ms_employee_detail>(); if (dtl_db != null) { dtl_db.range_id = 0; //di hide _item.selected_register_id = (dtl_db.asset_reg_location_id.HasValue) ? dtl_db.asset_reg_location_id.Value : 0; _item.selected_location_id = (dtl_db.location_id.HasValue) ? dtl_db.location_id.Value : 0; _item.selected_department_id = (dtl_db.department_id.HasValue) ? dtl_db.department_id.Value : 0; _item.selected_job_level_id = (dtl_db.job_level_id.HasValue) ? dtl_db.job_level_id.Value : 0; //_item.selected_user_type_id = (dtl_db.user_type_id.HasValue) ? dtl_db.user_type_id.Value : 0; _item.selected_fl_approver = (dtl_db.range_id.HasValue) ? ((dtl_db.range_id.Value > 0) ? 1 : 0) : 0; _item.selected_range_id = (dtl_db.range_id.HasValue) ? dtl_db.range_id.Value : 0; model.checkbox_approver.Add(new SelectedApprover_CheckBoxes { Checked = (dtl_db.range_id > 0), Value = "1" }); } else { _item.selected_register_id = 0; _item.selected_location_id = 0; _item.selected_department_id = 0; _item.selected_job_level_id = 0; _item.selected_user_type_id = 0; _item.selected_fl_approver = 0; //di hide _item.selected_range_id = 0; //di hide model.checkbox_approver.Add(new SelectedApprover_CheckBoxes { Checked = false, Value = "1" }); } model.employee_details.Add(_item); i_pos += 1; } return(View(model)); }
public ActionResult Login(string ReturnUrl = "", string token = "") { if (User.Identity.IsAuthenticated) { return(LogOut()); } #region "Process Token from Email Notification" if (token.Trim() != string.Empty) { try { token = token.Replace("plus", "+").Replace("equal", "="); token = App_Helpers.CryptorHelper.Decrypt(token, "MD5", true); string[] arrToken = token.Split('|'); if (arrToken.Count() > 0) { string controller = arrToken[0]; string actionname = arrToken[1]; string username = arrToken[2]; int companyid = Convert.ToInt32(arrToken[3]); int locationregid = Convert.ToInt32(arrToken[4]); //isi login form var user = (CustomMembershipUser)Membership.GetUser(username, false); if (user != null) { ASM_UI.Models.CustomSerializeViewModel userModel = new ASM_UI.Models.CustomSerializeViewModel() { user_id = user.user_id, user_name = user.user_name, user_password = user.user_password, user_type_id = user.user_type_id, employee_id = user.employee_id, employee_nik = user.employee_nik, employee_name = user.employee_name, employee_email = user.employee_email, fl_active = user.fl_active, RoleCode = user.Roles.Select(r => r.RoleCode).ToList() }; #region setelah login isi user profile USER_PROFILE UserProfile = Session["USER_PROFILE"] as USER_PROFILE; UserProfile.UserId = userModel.user_id; UserProfile.UserName = userModel.user_name; UserProfile.user_type_id = userModel.user_type_id; UserProfile.ms_user_type = _db.ms_user_type.Find(userModel.user_type_id); UserProfile.company_id = companyid; UserProfile.asset_reg_location_id = locationregid; UserProfile.register_location = _db.ms_asset_register_location.Find(UserProfile.asset_reg_location_id); UserProfile.employee_id = userModel.employee_id; UserProfile.UserFullName = userModel.employee_name; UserProfile.ms_employee = _db.ms_employee.Find(userModel.employee_id); ms_employee_detail employee_detail = _db.ms_employee_detail.Where(w => w.employee_id == userModel.employee_id && w.company_id == companyid).FirstOrDefault <ms_employee_detail>(); if (employee_detail != null) { UserProfile.CompanyName = employee_detail.ms_asmin_company.company_name; UserProfile.ms_department = employee_detail.ms_department; UserProfile.department_id = UserProfile.ms_department.department_id; UserProfile.ms_job_level = employee_detail.ms_job_level; UserProfile.job_level_id = UserProfile.ms_job_level.job_level_id; //UserProfile.ms_user_type = employee_detail.ms_user_type; //UserProfile.user_type_id = UserProfile.ms_user_type.user_type_id; if (employee_detail.ms_approval_range != null) { UserProfile.ms_approval_range = employee_detail.ms_approval_range; UserProfile.range_id = UserProfile.ms_approval_range.range_id; UserProfile.fl_approver = (UserProfile.range_id > 0); } } else //null tidak dapaat menu/role { UserProfile.CompanyName = ""; UserProfile.ms_department = new ms_department() { department_id = 0 }; UserProfile.department_id = UserProfile.ms_department.department_id; UserProfile.ms_job_level = new ms_job_level() { job_level_id = 0 }; UserProfile.job_level_id = UserProfile.ms_job_level.job_level_id; UserProfile.ms_user_type = new ms_user_type() { user_type_id = 0 }; UserProfile.user_type_id = UserProfile.ms_user_type.user_type_id; UserProfile.ms_approval_range = new ms_approval_range() { range_id = 0 }; UserProfile.range_id = UserProfile.ms_approval_range.range_id; UserProfile.fl_approver = false; } app_logwriter.ToLog(UserProfile.UserName + " logged-in with SessionID=" + Session.SessionID); app_logwriter.ToLog(string.Format("UserName:{0}, Employee:{1}, UserType={2}, JobLevel={3}, Department={4}, Company={5}, Location={6}, Register={7}" , UserProfile.UserName , UserProfile.ms_employee.employee_name , UserProfile.ms_user_type.user_type_name , UserProfile.ms_job_level.job_level_name , UserProfile.ms_department.department_name , UserProfile.CompanyName , UserProfile.location_name , UserProfile.register_location.asset_reg_location_name)); #endregion string userData = JsonConvert.SerializeObject(userModel); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket ( 1, username.ToString(), DateTime.Now, DateTime.Now.AddHours(5), false, userData ); string enTicket = FormsAuthentication.Encrypt(authTicket); string cookie_name = app_setting.COOKIE_NAME + UserProfile.UserName; //HttpCookie faCookie = new HttpCookie(cookie_name, enTicket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, enTicket); Response.Cookies.Add(faCookie); } return(RedirectToAction(actionname, controller)); } } catch (Exception ex) { app_logwriter.ToLog("Token Invalid:" + ex.Message); ModelState.AddModelError("", "Token Invalid."); } } #endregion string controllerName = RouteData.Values["controller"].ToString().ToLower(); string actionName = RouteData.Values["action"].ToString().ToLower(); ReturnUrl = (controllerName.Equals("account") && actionName.Equals("login")) ? "/" : ReturnUrl; var loginView = new AccountLoginViewModel() { company_id = 0, company_list = _db.ms_asmin_company.Where(r => r.fl_active == true && r.deleted_date == null).ToList(), asset_reg_location_id = 0, asset_register_location_list = _db.ms_asset_register_location.Where(r => r.fl_active == true && r.deleted_date == null).ToList(), user_type_id = 0, user_type_list = _db.ms_user_type.Where(r => r.fl_active == true && r.deleted_date == null).ToList(), remember_me = true, return_url = ReturnUrl, }; ViewBag.ReturnUrl = loginView.return_url; return(View(loginView)); }
public ActionResult Login(AccountLoginViewModel loginView, string ReturnUrl = "") { try { if (ModelState.IsValid) { if (Membership.ValidateUser(loginView.UserName, App_Helpers.CryptorHelper.Encrypt(loginView.Password, "MD5", true))) { var m_user = (CustomMembershipUser)Membership.GetUser(loginView, false); if (m_user != null) { ASM_UI.Models.CustomSerializeViewModel userModel = new ASM_UI.Models.CustomSerializeViewModel() { user_id = m_user.user_id, user_name = m_user.user_name, user_password = m_user.user_password, user_type_id = loginView.user_type_id, employee_id = m_user.employee_id, employee_nik = m_user.employee_nik, employee_name = m_user.employee_name, employee_email = m_user.employee_email, fl_active = m_user.fl_active, RoleCode = m_user.Roles.Select(r => r.RoleCode).ToList() }; #region setelah login isi user profile USER_PROFILE UserProfile = Session["USER_PROFILE"] as USER_PROFILE; UserProfile.UserId = userModel.user_id; UserProfile.UserName = userModel.user_name; UserProfile.user_type_id = userModel.user_type_id; UserProfile.ms_user_type = _db.ms_user_type.Find(userModel.user_type_id); UserProfile.company_id = loginView.company_id; UserProfile.asset_reg_location_id = loginView.asset_reg_location_id; UserProfile.register_location = _db.ms_asset_register_location.Find(UserProfile.asset_reg_location_id); UserProfile.employee_id = userModel.employee_id; UserProfile.UserFullName = userModel.employee_name; UserProfile.ms_employee = _db.ms_employee.Find(userModel.employee_id); ms_employee_detail employee_detail = _db.ms_employee_detail.Where(w => w.employee_id == userModel.employee_id && w.company_id == UserProfile.company_id && w.asset_reg_location_id == UserProfile.asset_reg_location_id ).FirstOrDefault <ms_employee_detail>(); if (employee_detail != null) { UserProfile.CompanyName = employee_detail.ms_asmin_company.company_name; UserProfile.ms_department = employee_detail.ms_department; UserProfile.department_id = UserProfile.ms_department.department_id; UserProfile.ms_job_level = employee_detail.ms_job_level; UserProfile.job_level_id = UserProfile.ms_job_level.job_level_id; //UserProfile.ms_user_type = employee_detail.ms_user_type; //UserProfile.user_type_id = UserProfile.ms_user_type.user_type_id; UserProfile.location_id = employee_detail.location_id; ms_asset_location asset_location = _db.ms_asset_location.Where(w => w.location_id == UserProfile.location_id).FirstOrDefault <ms_asset_location>(); UserProfile.location_name = asset_location.location_name; if (employee_detail.ms_approval_range != null) { UserProfile.ms_approval_range = employee_detail.ms_approval_range; UserProfile.range_id = UserProfile.ms_approval_range.range_id; UserProfile.fl_approver = (UserProfile.range_id > 0); } } else //null tidak dapaat menu/role { UserProfile.CompanyName = ""; UserProfile.ms_department = new ms_department() { department_id = 0 }; UserProfile.department_id = UserProfile.ms_department.department_id; UserProfile.ms_job_level = new ms_job_level() { job_level_id = 0 }; UserProfile.job_level_id = UserProfile.ms_job_level.job_level_id; UserProfile.ms_user_type = new ms_user_type() { user_type_id = 0 }; UserProfile.user_type_id = UserProfile.ms_user_type.user_type_id; UserProfile.ms_approval_range = new ms_approval_range() { range_id = 0 }; UserProfile.range_id = UserProfile.ms_approval_range.range_id; UserProfile.fl_approver = false; } app_logwriter.ToLog(UserProfile.UserName + " logged-in with SessionID=" + Session.SessionID); app_logwriter.ToLog(string.Format("UserName:{0}, Employee:{1}, UserType={2}, JobLevel={3}, Department={4}, Company={5}, Location={6}, Register={7}" , UserProfile.UserName , UserProfile.ms_employee.employee_name , UserProfile.ms_user_type.user_type_name , UserProfile.ms_job_level.job_level_name , UserProfile.ms_department.department_name , UserProfile.CompanyName , UserProfile.location_name , UserProfile.register_location.asset_reg_location_name)); #endregion string userData = JsonConvert.SerializeObject(userModel); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, loginView.UserName, DateTime.Now, DateTime.Now.AddHours(5), false, userData ); string enTicket = FormsAuthentication.Encrypt(authTicket); string cookie_name = app_setting.COOKIE_NAME + UserProfile.UserName; //HttpCookie faCookie = new HttpCookie(cookie_name, enTicket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, enTicket); Response.Cookies.Add(faCookie); } else { ModelState.AddModelError("", "Something Wrong : User not Found or user login not matched."); //throw new Exception("Something Wrong : User not Found or user login not matched."); } string controllerName = RouteData.Values["controller"].ToString().ToLower(); string actionName = RouteData.Values["action"].ToString().ToLower(); ReturnUrl = (controllerName.Equals("account") && actionName.Equals("login")) ? "/" : ReturnUrl; //if (Url.IsLocalUrl(ReturnUrl)) if (!string.IsNullOrWhiteSpace(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { return(RedirectToAction("Index")); } } else { ModelState.AddModelError("", "Something Wrong : Username/nik or Password invalid."); } } else { ModelState.AddModelError("", "Something Wrong : Username/nik or Password invalid."); } } catch (Exception _ex) { //ModelState.AddModelError("", "Invalid Login." + ex.Message); App_Helpers.app_logwriter.ToLog("Invalid Login." + _ex.Message); ModelState.AddModelError("", "Invalid Login."); } if (loginView.company_list == null || loginView.company_list.Count == 0) { loginView.company_list = _db.ms_asmin_company.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (loginView.asset_register_location_list == null || loginView.asset_register_location_list.Count == 0) { loginView.asset_register_location_list = _db.ms_asset_register_location.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (loginView.user_type_list == null || loginView.user_type_list.Count == 0) { loginView.user_type_list = _db.ms_user_type.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } return(View(loginView)); }