public ActionResult DeleteConfirmed(int id) { ms_asset_location ms_asset_location = db.ms_asset_location.Find(id); db.ms_asset_location.Remove(ms_asset_location); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "location_id,location_code,location_name,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] ms_asset_location ms_asset_location) { if (ModelState.IsValid) { db.Entry(ms_asset_location).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ms_asset_location)); }
public ActionResult Create([Bind(Include = "location_id,location_code,location_name,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] ms_asset_location ms_asset_location) { if (ModelState.IsValid) { db.ms_asset_location.Add(ms_asset_location); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ms_asset_location)); }
// GET: asset_location/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ms_asset_location ms_asset_location = db.ms_asset_location.Find(id); if (ms_asset_location == null) { return(HttpNotFound()); } return(View(ms_asset_location)); }
public ActionResult Create([Bind(Include = "asset_parent_id,asset_number,company_id,asset_reg_location_id,asset_reg_pic_id,category_id,asset_po_number,asset_do_number,asset_name,asset_merk,asset_serial_number,vendor_id,asset_receipt_date,location_id,department_id,employee_id,asset_description,asset_file_attach")] subasset_registrationViewModel asset_reg) { if (ModelState.IsValid) { using (DbContextTransaction dbTran = db.Database.BeginTransaction()) { try { #region SUBASSET tr_asset_registration asset_parent = db.tr_asset_registration.Find(asset_reg.asset_parent_id); int _last_no = db.tr_asset_registration.Where(a => a.asset_parent_id == asset_reg.asset_parent_id).Count(); /*no aktifa seq*/ _last_no++; string no_activa = _last_no.ToString().PadLeft(2, '0'); string[] complex_no = asset_parent.asset_number.Split(new char[3] { '.', '-', '/' }); asset_reg.asset_number = complex_no[0] + "-" + no_activa; tr_asset_registration ass_reg = new tr_asset_registration(); ass_reg.asset_type_id = (int)Enum_asset_type_Key.AssetChild; //child ass_reg.asset_parent_id = asset_reg.asset_parent_id; ass_reg.tr_asset_registration2 = asset_parent; ass_reg.asset_number = asset_reg.asset_number; ass_reg.company_id = asset_reg.company_id; ass_reg.asset_reg_location_id = asset_reg.asset_reg_location_id; ass_reg.asset_reg_pic_id = asset_reg.asset_reg_pic_id; ass_reg.category_id = asset_reg.category_id; ass_reg.asset_po_number = asset_reg.asset_po_number; ass_reg.asset_do_number = asset_reg.asset_do_number; ass_reg.asset_name = asset_reg.asset_name; ass_reg.asset_merk = asset_reg.asset_merk; ass_reg.asset_serial_number = asset_reg.asset_serial_number; ass_reg.vendor_id = asset_reg.vendor_id; ass_reg.asset_receipt_date = asset_reg.asset_receipt_date; ass_reg.location_id = asset_reg.location_id; ass_reg.current_location_id = asset_reg.location_id; ass_reg.department_id = asset_reg.department_id; ass_reg.current_department_id = asset_reg.department_id; ass_reg.asset_description = asset_reg.asset_description; ass_reg.employee_id = asset_reg.employee_id; ass_reg.current_employee_id = asset_reg.employee_id; ass_reg.fl_active = true; ass_reg.created_date = DateTime.Now; ass_reg.created_by = UserProfile.UserId; ass_reg.updated_date = DateTime.Now; ass_reg.updated_by = UserProfile.UserId; ass_reg.deleted_date = null; ass_reg.deleted_by = null; ass_reg.org_id = UserProfile.OrgId; ass_reg = db.tr_asset_registration.Add(ass_reg); db.SaveChanges(); #endregion #region FILEASSET //ass_reg.asset_file_attach = asset_reg.asset_file_attach; if (Request.Files.Count > 0) { //var file = Request.Files[0]; app_root_path = Server.MapPath("~/"); if (string.IsNullOrWhiteSpace(base_image_path)) { base_image_path = subasset_registrationViewModel.path_file_asset; } string img_path = Server.MapPath(base_image_path); if (!Directory.Exists(img_path)) { Directory.CreateDirectory(img_path); } var file = Request.Files["asset_img_file"]; if (file != null && file.ContentLength > 0) { var fileName = "asset" + ass_reg.asset_id.ToString() + "_" + Path.GetFileName(file.FileName); var path = Path.Combine(img_path, fileName); file.SaveAs(path); tr_asset_image _ass_img = new tr_asset_image() { asset_id = ass_reg.asset_id, asset_img_address = fileName, asset_qrcode = GenerateQRCode(asset_reg.asset_number) }; db.tr_asset_image.Add(_ass_img); db.SaveChanges(); } } #endregion dbTran.Commit(); } catch (Exception _exc) { dbTran.Rollback(); throw new Exception("Fail to save create new sub-asset." + _exc.Message); } } #region "Send Email Notif to accounting department" try { ms_disposal_type Dept3 = db.ms_disposal_type.Find(3); int acct_id = Convert.ToInt32(Dept3.disposal_by_dept_id); var _qry = (from dept in db.ms_department.Where(dept => dept.department_id == acct_id) select dept).ToList().FirstOrDefault(); if (_qry == null) { throw new Exception("Department not found"); } sy_email_log sy_email_log = new sy_email_log(); sy_email_log.elog_to = _qry.department_email; sy_email_log.elog_subject = string.Format("Sub Asset Registration"); sy_email_log.elog_template = "EMAIL_TEMPLATE_90"; var _bodymail = app_setting.APPLICATION_SETTING.Where(c => c.app_key.Contains("EMAIL_TEMPLATE_90")).FirstOrDefault(); if (_bodymail == null) { throw new Exception("Email Template 01 not found"); } string strBodyMail = _bodymail.app_value; strBodyMail = strBodyMail.Replace("[to]", _qry.department_name + " Department"); strBodyMail = strBodyMail.Replace("[action]", "Dispose"); strBodyMail = strBodyMail.Replace("[assetnumber]", asset_reg.asset_number); strBodyMail = strBodyMail.Replace("[assetname]", asset_reg.asset_name); ms_asset_location loc = db.ms_asset_location.Find(asset_reg.location_id); if (loc == null) { throw new Exception("Sub Asset Location not found"); } strBodyMail = strBodyMail.Replace("[assetlocation]", loc.location_name); ms_department deptment = db.ms_department.Find(asset_reg.department_id); if (deptment == null) { throw new Exception("Department not found"); } strBodyMail = strBodyMail.Replace("[department]", deptment.department_name); sy_email_log.elog_body = strBodyMail; var EmailHelper = new EmailHelper() { ToAddress = sy_email_log.elog_to, Email_Template = sy_email_log.elog_template, MailSubject = sy_email_log.elog_subject, MailBody = sy_email_log.elog_body }; EmailHelper.Send(); } catch { } #endregion return(RedirectToAction("Index")); } #region complete the VM if (asset_reg.asset_parent_list == null) { asset_reg.asset_parent_list = db.tr_asset_registration.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (asset_reg.company_list == null) { asset_reg.company_list = db.ms_asmin_company.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (asset_reg.asset_reg_location_list == null) { asset_reg.asset_reg_location_list = db.ms_asset_register_location.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (asset_reg.asset_reg_pic_list == null) { asset_reg.asset_reg_pic_list = db.ms_asset_register_pic.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (asset_reg.asset_category_list == null) { asset_reg.asset_category_list = db.ms_asset_category.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (asset_reg.vendor_list == null) { asset_reg.vendor_list = db.ms_vendor.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (asset_reg.asset_location_list == null) { asset_reg.asset_location_list = db.ms_asset_location.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (asset_reg.department_list == null) { asset_reg.department_list = db.ms_department.Where(r => r.fl_active == true && r.deleted_date == null).ToList(); } if (asset_reg.employee_list == null) { asset_reg.employee_list = db.ms_employee.AsEnumerable().Where(r => r.fl_active == true && r.deleted_date == null).Select(e => new ms_employee { employee_id = e.employee_id, employee_name = "[" + e.employee_nik + "] - " + e.employee_name, employee_email = e.employee_email }).ToList(); } #endregion return(View(asset_reg)); }
public JsonResult CrudAssetLoc() { if (UserProfile.UserId != 0) { if (Request.Form["oper"] == "add") { //prepare for insert data ms_asset_location ms_loc = new ms_asset_location(); ms_loc.asset_reg_location_id = Convert.ToInt32(Request.Form["asset_reg_location_name"]); ms_loc.location_code = Request.Form["location_code"]; ms_loc.location_name = Request.Form["location_name"]; ms_loc.fl_active = Request.Form["rec_isactive"] == "Yes" ? true : false; //ms_loc.fl_active = true; ms_loc.created_by = UserProfile.UserId; ms_loc.created_date = DateTime.Now; ms_loc.updated_by = UserProfile.UserId; ms_loc.updated_date = DateTime.Now; ms_loc.org_id = UserProfile.OrgId; ms_loc.deleted_by = null; ms_loc.deleted_date = null; //db.ms_asset_location.Add(ms_loc); db.Entry(ms_loc).State = EntityState.Added; db.SaveChanges(); return(Json("Insert", JsonRequestBehavior.AllowGet)); } else if (Request.Form["oper"] == "edit") { if (IsNumeric(Request.Form["location_id"].ToString())) { //prepare for update data int id = Convert.ToInt32(Request.Form["location_id"]); ms_asset_location ms_loc = db.ms_asset_location.Find(id); ms_loc.asset_reg_location_id = Convert.ToInt32(Request.Form["asset_reg_location_name"]); ms_loc.location_code = Request.Form["location_code"]; ms_loc.location_name = Request.Form["location_name"]; ms_loc.fl_active = Request.Form["rec_isactive"] == "Yes" ? true : false; //ms_loc.fl_active = true; ms_loc.updated_by = UserProfile.UserId; ms_loc.updated_date = DateTime.Now; ms_loc.org_id = UserProfile.OrgId; ms_loc.deleted_by = null; ms_loc.deleted_date = null; db.Entry(ms_loc).State = EntityState.Modified; db.SaveChanges(); return(Json("Update", JsonRequestBehavior.AllowGet)); } else { //prepare for insert data ms_asset_location ms_loc = new ms_asset_location(); ms_loc.location_code = Request.Form["location_code"]; ms_loc.location_name = Request.Form["location_name"]; ms_loc.fl_active = Request.Form["rec_isactive"] == "Yes" ? true : false; //ms_loc.fl_active = true; ms_loc.created_by = UserProfile.UserId; ms_loc.created_date = DateTime.Now; ms_loc.updated_by = UserProfile.UserId; ms_loc.updated_date = DateTime.Now; ms_loc.org_id = UserProfile.OrgId; ms_loc.deleted_by = null; ms_loc.deleted_date = null; //db.ms_asset_location.Add(ms_loc); db.Entry(ms_loc).State = EntityState.Added; db.SaveChanges(); return(Json("Insert", JsonRequestBehavior.AllowGet)); } } else { if (Request.Form["oper"] == "del") { //for delete process string ids = Request.Form["id"]; string[] values = ids.Split(','); for (int i = 0; i < values.Length; i++) { values[i] = values[i].Trim(); //prepare for soft delete data int id = Convert.ToInt32(values[i]); ms_asset_location ms_loc = db.ms_asset_location.Find(id); ms_loc.fl_active = false; ms_loc.deleted_by = UserProfile.UserId; //userid ms_loc.deleted_date = DateTime.Now; db.Entry(ms_loc).State = EntityState.Modified; db.SaveChanges(); } return(Json("Delete", JsonRequestBehavior.AllowGet)); } else { return(Json("Error", JsonRequestBehavior.AllowGet)); } } } else { return(Json("Session", JsonRequestBehavior.AllowGet)); } }
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)); }