public ActionResult Create([Bind(Include = "user_id,user_name,user_password,user_type_id,employee_id,fl_active")] user_accountViewModel user_acc) { if (ModelState.IsValid) { using (var transaction = db.Database.BeginTransaction()) { try { ms_employee emp = db.ms_employee.Find(user_acc.employee_id); if (emp == null) { throw new Exception("Employee not found " + user_acc.employee_id.ToString()); } else { user_acc.employee_nik = emp.employee_nik; user_acc.employee_name = emp.employee_name; user_acc.employee_email = emp.employee_email; emp.fl_active = true; emp.updated_by = UserProfile.UserId; emp.updated_date = DateTime.Now; emp.deleted_by = null; emp.deleted_date = null; db.Entry(emp).State = EntityState.Modified; ms_user ms_user = new ms_user() { user_name = user_acc.user_name, user_password = App_Helpers.CryptorHelper.Encrypt(user_acc.user_password, "MD5", true), user_type_id = user_acc.user_type_id, employee_id = emp.employee_id, fl_active = user_acc.fl_active, created_by = UserProfile.UserId, created_date = DateTime.Now, updated_by = UserProfile.UserId, updated_date = DateTime.Now, deleted_by = null, deleted_date = null }; db.ms_user.Add(ms_user); 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(user_acc)); }
public ActionResult Edit([Bind(Include = "warranty_id, asset_parent_id, warranty_number, warranty_item_name, warranty_date, warranty_exp_date, warranty_description")] asset_warrantyViewModel asset_wrt) { if (asset_wrt.warranty_date > DateTime.Today) { ModelState.AddModelError("warranty_date", "Please enter a valid date."); } if (asset_wrt.warranty_date > asset_wrt.warranty_exp_date) { ModelState.AddModelError("warranty_exp_date", "Warranty expired date must be after warranty date."); } if (ModelState.IsValid && asset_wrt.warranty_id > 0) { tr_asset_warranty ass_warranty = db.tr_asset_warranty.Find(asset_wrt.warranty_id); ass_warranty.warranty_number = asset_wrt.warranty_number; ass_warranty.warranty_item_name = asset_wrt.warranty_item_name; ass_warranty.warranty_date = asset_wrt.warranty_date; ass_warranty.warranty_exp_date = asset_wrt.warranty_exp_date; ass_warranty.warranty_description = asset_wrt.warranty_description; ass_warranty.fl_active = true; ass_warranty.updated_date = DateTime.Now; ass_warranty.updated_by = UserProfile.UserId; ass_warranty.deleted_date = null; ass_warranty.deleted_by = null; ass_warranty.org_id = UserProfile.OrgId; db.Entry(ass_warranty).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } tr_asset_registration ass_reg = db.tr_asset_registration.Find(asset_wrt.asset_parent_id); asset_wrt.FormMode = EnumFormModeKey.Form_Edit; asset_wrt.asset_parent_id = (int)ass_reg.asset_id; asset_wrt.asset_parent = ass_reg; ms_vendor msvendor = db.ms_vendor.Find(ass_reg.vendor_id); asset_wrt.vendor_name = msvendor.vendor_name; //Data view edit asset_wrt.asset_warranty_list = (from aw in db.tr_asset_warranty where (aw.fl_active == true && aw.deleted_date == null && aw.asset_id == asset_wrt.asset_parent_id) select aw).ToList <tr_asset_warranty>(); return(View(asset_wrt)); }
public ActionResult Edit([Bind(Include = "license_id, asset_parent_id, license_number, license_name, license_issued_by, license_date, license_exp_date, license_description")] asset_licenseViewModel asset_lcs) { if (asset_lcs.license_date > DateTime.Today) { ModelState.AddModelError("license_date", "Please enter a valid date."); } if (asset_lcs.license_date > asset_lcs.license_exp_date) { ModelState.AddModelError("license_exp_date", "license expired date must be after license date."); } if (ModelState.IsValid && asset_lcs.license_id > 0) { tr_asset_license ass_license = db.tr_asset_license.Find(asset_lcs.license_id); ass_license.license_number = asset_lcs.license_number; ass_license.license_name = asset_lcs.license_name; ass_license.license_issued_by = asset_lcs.license_issued_by; ass_license.license_date = asset_lcs.license_date; ass_license.license_exp_date = asset_lcs.license_exp_date; ass_license.license_description = asset_lcs.license_description; ass_license.fl_active = true; ass_license.updated_date = DateTime.Now; ass_license.updated_by = UserProfile.UserId; ass_license.deleted_date = null; ass_license.deleted_by = null; ass_license.org_id = UserProfile.OrgId; db.Entry(ass_license).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } tr_asset_registration ass_reg = db.tr_asset_registration.Find(asset_lcs.asset_parent_id); asset_lcs.FormMode = EnumFormModeKey.Form_Edit; asset_lcs.asset_parent_id = (int)ass_reg.asset_id; asset_lcs.asset_parent = ass_reg; //Data view edit asset_lcs.asset_license_list = (from aw in db.tr_asset_license where (aw.fl_active == true && aw.deleted_date == null && aw.asset_id == asset_lcs.asset_parent_id) select aw).ToList <tr_asset_license>(); return(View(asset_lcs)); }
public ActionResult ChangePassword(AccountChangePasswordViewModel model) { ms_user _user = (from t in _db.ms_user where t.user_name == model.UserName && t.user_id == model.user_id select t).SingleOrDefault <ms_user>(); if (_user != null) { if (model.NewPassword.ToLower().Equals(model.ConfirmPassword.ToLower())) { _user.user_password = App_Helpers.CryptorHelper.Encrypt(model.NewPassword, "MD5", true); _user.fl_active = true; _user.updated_by = UserProfile.UserId; _user.updated_date = DateTime.Now; _user.deleted_by = null; _user.deleted_date = null; _db.Entry(_user).State = EntityState.Modified; _db.SaveChanges(); ViewBag.ErrMessage = "Your password has been successfully changed."; RedirectToAction("Index", "Account", null); //RedirectToAction("Logout", "Account", null); } else { //beda confirm ViewBag.ErrMessage = "[New Password] not matched to [Confirm Password]."; } } else { ViewBag.ErrMessage = "User " + _user.user_name + " not found..."; } return(View(model)); }
public ActionResult Edit([Bind(Include = "job_level_id,job_level_code,job_level_name,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] ms_job_level ms_job_level) { if (ModelState.IsValid) { db.Entry(ms_job_level).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ms_job_level)); }
public ActionResult Edit([Bind(Include = "approval_id,request_id,approval_date,approval_location_id,approval_dept_id,approval_employee_id,approval_level_id,approval_status_id,approval_noted,approval_suggestion_id,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deteled_by,org_id")] tr_disposal_approval tr_disposal_approval) { if (ModelState.IsValid) { db.Entry(tr_disposal_approval).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tr_disposal_approval)); }
public ActionResult Edit([Bind(Include = "asset_id,asset_img_address")] tr_asset_image tr_asset_image) { if (ModelState.IsValid) { db.Entry(tr_asset_image).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tr_asset_image)); }
public ActionResult Edit([Bind(Include = "depreciation_id,asset_id,depreciation_type_id,asset_original_value,asset_original_currency_id,Currency_kurs,asset_book_value,fis_asset_residu_value,fis_asset_usefull_life,fis_ddb_precentage,mkt_asset_residu_value,mkt_asset_usefull_life,mkt_ddb_percentage,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] tr_depreciation tr_depreciation) { if (ModelState.IsValid) { db.Entry(tr_depreciation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tr_depreciation)); }
public ActionResult Edit([Bind(Include = "request_id,asset_id,request_date,request_emp_id,request_dept_id,request_location_id,request_level_id,transfer_to_location_id,transfer_to_dept_id,transfer_to_emp_id,fl_approval,approval_date,request_status,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] tr_mutation_request tr_mutation_request) { if (ModelState.IsValid) { db.Entry(tr_mutation_request).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tr_mutation_request)); }
public ActionResult Edit([Bind(Include = "depreciation_detail_id,depreciation_id,depreciation_type_id,period,period_year,period_month,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] tr_depreciation_detail tr_depreciation_detail) { if (ModelState.IsValid) { db.Entry(tr_depreciation_detail).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tr_depreciation_detail)); }
public ActionResult Edit([Bind(Include = "disposal_bap_id,disposal_id,disposal_dept_id,fl_disposal_process,disposal_bap_date,disposal_bap_description,disposal_upload_address,disposal_change_dept_id,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] tr_disposal_bap tr_disposal_bap) { if (ModelState.IsValid) { db.Entry(tr_disposal_bap).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tr_disposal_bap)); }
public ActionResult Edit([Bind(Include = "disposal_type_id,disposal_type_code,disposal_type_name,disposal_by_dept_id")] ms_disposal_type ms_disposal_type) { if (ModelState.IsValid) { db.Entry(ms_disposal_type).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ms_disposal_type)); }
public ActionResult Edit([Bind(Include = "employee_id,employee_nik,employee_name,employee_email,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id,ip_address")] ms_employee ms_employee) { if (ModelState.IsValid) { db.Entry(ms_employee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ms_employee)); }
public ActionResult Edit([Bind(Include = "asset_reg_pic_id,asset_reg_pic_code,asset_reg_pic_name,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] ms_asset_register_pic ms_asset_register_pic) { if (ModelState.IsValid) { db.Entry(ms_asset_register_pic).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ms_asset_register_pic)); }
public ActionResult Edit([Bind(Include = "asset_id,asset_type_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,asset_description,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] tr_asset_registration tr_asset_registration) { if (ModelState.IsValid) { db.Entry(tr_asset_registration).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tr_asset_registration)); }
public ActionResult Edit([Bind(Include = "range_id,range_type,range_code,range_min,range_max,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] ms_approval_range ms_approval_range) { if (ModelState.IsValid) { db.Entry(ms_approval_range).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ms_approval_range)); }
public ActionResult Edit([Bind(Include = "warranty_id,asset_id,warranty_number,warranty_item_name,warranty_date,warranty_exp_date,warranty_description,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] tr_asset_warranty tr_asset_warranty) { if (ModelState.IsValid) { db.Entry(tr_asset_warranty).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tr_asset_warranty)); }
public ActionResult Edit([Bind(Include = "disposal_id,request_id,fl_pic_asset_comfirm,pic_asset_confirm_date,pic_asset_employee_id,pic_asset_level_id,pic_asset_received_date,pic_asset_received_employee_id,pic_asset_received_level_id,disposal_suggestion_id,disposal_sent_dept_id,disposal_sent_date,user_asset_received_employee_id,user_asset_received_level_id,user_asset_received_date,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] tr_disposal_process tr_disposal_process) { if (ModelState.IsValid) { db.Entry(tr_disposal_process).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tr_disposal_process)); }
public ActionResult Edit([Bind(Include = "company_id,company_code,company_name,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] ms_asmin_company ms_asmin_company) { if (ModelState.IsValid) { db.Entry(ms_asmin_company).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ms_asmin_company)); }
public ActionResult Edit([Bind(Include = "depreciation_type_id,depreciation_type_code,depreciation_type_name,fl_active,created_date,created_by,update_date,update_by,deleted_date,deleted_by,org_id")] ms_depreciation_type ms_depreciation_type) { if (ModelState.IsValid) { db.Entry(ms_depreciation_type).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ms_depreciation_type)); }
public ActionResult Edit([Bind(Include = "menu_id,menu_code,menu_name,module_id,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id,menu_url,rec_order")] ms_menu ms_menu) { if (ModelState.IsValid) { db.Entry(ms_menu).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ms_menu)); }
public ActionResult Edit([Bind(Include = "license_id,asset_id,license_number,license_name,license_issued_by,license_date,license_exp_date,license_description,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] tr_asset_license tr_asset_license) { if (ModelState.IsValid) { db.Entry(tr_asset_license).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tr_asset_license)); }
public ActionResult Edit([Bind(Include = "approval_status_id,approval_status_code,approval_status_name")] ms_approval_status ms_approval_status) { if (ModelState.IsValid) { db.Entry(ms_approval_status).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ms_approval_status)); }
public ActionResult Edit([Bind(Include = "vendor_id,vendor_code,vendor_name,vendor_address,country_id,vendor_phone,vendor_mail,vendor_cp_name,vendor_cp_phone,vendor_cp_mail,vendor_description,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] ms_vendor ms_vendor) { if (ModelState.IsValid) { db.Entry(ms_vendor).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.country_id = new SelectList(db.ms_country, "country_id", "country_code", ms_vendor.country_id); return(View(ms_vendor)); }
public ActionResult Edit([Bind(Include = "user_id,user_name,user_password,employee_id,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id")] ms_user ms_user) { if (ModelState.IsValid) { db.Entry(ms_user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.employee_id = new SelectList(db.ms_employee, "employee_id", "employee_nik", ms_user.employee_id); return(View(ms_user)); }
public ActionResult SaveData(string NewName) { int idC; int.TryParse(Request.Form["insuranceID"], out idC); ms_insurance ms_insurance = new ms_insurance(); ms_insurance.insurance_id = idC; ms_insurance.insurance_code = Request.Form["insuranceCode"]; ms_insurance.insurance_name = Request.Form["insuranceName"]; ms_insurance.insurance_address = Request.Form["insuranceAddress"]; ms_insurance.country_id = Convert.ToInt32(Request.Form["Country"]); ms_insurance.insurance_phone = Request.Form["insurancePhone"]; ms_insurance.insurance_mail = Request.Form["insuranceMail"]; ms_insurance.insurance_cp_name = Request.Form["insuranceCPName"]; ms_insurance.insurance_cp_phone = Request.Form["insuranceCPPhone"]; ms_insurance.insurance_cp_mail = Request.Form["insuranceCPMail"]; ms_insurance.insurance_description = Request.Form["insuranceDescription"]; ms_insurance.fl_active = Request.Form["rec_isactive"] == "Yes" ? true : false; ms_insurance.deleted_by = null; ms_insurance.deleted_date = null; if (idC == 0) { ms_insurance.created_by = UserProfile.UserId; ms_insurance.created_date = DateTime.Now; ms_insurance.org_id = UserProfile.OrgId; db.Entry(ms_insurance).State = EntityState.Added; db.SaveChanges(); return(Json("Insert", JsonRequestBehavior.AllowGet)); } else { ms_insurance.updated_by = UserProfile.UserId; ms_insurance.updated_date = DateTime.Now; db.Entry(ms_insurance).State = EntityState.Modified; db.SaveChanges(); return(Json("Update", JsonRequestBehavior.AllowGet)); } }
public ActionResult Edit([Bind(Include = "app_id,app_key,app_value,app_desc")] sy_app_setting sy_app_setting) { if (ModelState.IsValid) { sy_app_setting.fl_active = true; sy_app_setting.created_date = DateTime.Now; sy_app_setting.created_by = UserProfile.UserId; db.Entry(sy_app_setting).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sy_app_setting)); }
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)); }
public ActionResult Edit([Bind(Include = "menu_id,user_type_id,job_level_id")] ms_user_rights ms_user_rights) { if (ModelState.IsValid) { ms_user_rights.fl_active = true; ms_user_rights.updated_date = DateTime.Now; ms_user_rights.updated_by = 1; ms_user_rights.deleted_date = null; ms_user_rights.deleted_by = null; ms_user_rights.org_id = 0; db.Entry(ms_user_rights).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.job_level_id = new SelectList(db.ms_job_level, "job_level_id", "job_level_code", ms_user_rights.job_level_id); ViewBag.user_type_id = new SelectList(db.ms_user_type, "user_type_id", "user_type_code", ms_user_rights.user_type_id); return(View(ms_user_rights)); }
public ActionResult Approval([Bind(Include = "request_id, approval_id, fl_approval, approval_suggestion_id, approval_noted, asset_number,asset_name, location_name, department_name, fl_SuggestionChanges")] disposalViewModel disposal_req) { if (disposal_req.fl_approval != null) { if (disposal_req.fl_approval == true) { if (disposal_req.approval_suggestion_id == null || disposal_req.approval_suggestion_id == 0) { ModelState.AddModelError("approval_suggestion_id", "Suggestion is Mandatory."); } } } else if (disposal_req.approval_noted == null || disposal_req.approval_noted.Trim() == string.Empty) { ModelState.AddModelError("fl_approval", "Approval is Mandatory."); ModelState.AddModelError("approval_noted", "Reject Reason is Mandatory."); } //update disposal request and approval data with transaction if (ModelState.IsValid) { using (var transaction = db.Database.BeginTransaction()) { try { bool iscomplete = false; #region "Save update Request Disposal" tr_disposal_request disposal_request = db.tr_disposal_request.Find(disposal_req.request_id); var doneapp = (from app in db.tr_disposal_approval where (app.approval_date == null && app.fl_active == true && app.deleted_date == null && app.request_id == disposal_req.request_id) select app).ToList(); if (disposal_req.fl_SuggestionChanges == false) { disposal_request.fl_approval = disposal_req.fl_approval; if (disposal_req.fl_approval == true) { if (doneapp.Count == 1) { disposal_request.request_status_id = 5;//complete iscomplete = true; } else { disposal_request.request_status_id = 2;//approve } } else { disposal_request.request_status_id = 3; //reject } disposal_request.approval_date = DateTime.Now; disposal_request.updated_date = DateTime.Now; disposal_request.update_by = UserProfile.UserId; disposal_request.deleted_date = null; disposal_request.deleted_by = null; db.Entry(disposal_request).State = EntityState.Modified; db.SaveChanges(); } #endregion #region "Save update Approval Disposal" tr_disposal_approval disposal_approval = db.tr_disposal_approval.Find(disposal_req.approval_id); if (disposal_req.fl_approval == true) { disposal_approval.approval_status_id = 2;//approve disposal_approval.approval_suggestion_id = disposal_req.approval_suggestion_id; } else { disposal_approval.approval_status_id = 3; //reject disposal_approval.approval_noted = disposal_req.approval_noted; disposal_approval.fl_active = false; //kembalikan status announcement ke suggestion terakhir tr_disposal_announcement disposal_ann_old = (from tda in db.tr_disposal_announcement where tda.request_id == disposal_approval.request_id && tda.fl_suggestion_changes == true select tda).FirstOrDefault(); disposal_ann_old.fl_suggestion_changes = false; disposal_ann_old.fl_active = true; disposal_ann_old.updated_date = DateTime.Now; disposal_ann_old.updated_by = UserProfile.UserId; db.Entry(disposal_ann_old).State = EntityState.Modified; db.SaveChanges(); } disposal_approval.approval_date = DateTime.Now; disposal_approval.approval_location_id = UserProfile.asset_reg_location_id; disposal_approval.updated_date = DateTime.Now; disposal_approval.updated_by = UserProfile.UserId; disposal_approval.deleted_date = null; disposal_approval.deteled_by = null; db.Entry(disposal_approval).State = EntityState.Modified; db.SaveChanges(); #endregion if (disposal_req.fl_approval == true) { //cek untuk disposal changes: site atau ho tr_asset_registration assetreg = db.tr_asset_registration.Find(disposal_request.asset_id); if (doneapp.Count == 1) { iscomplete = true; } if (!iscomplete && ((assetreg.location_id != 1 && disposal_req.fl_SuggestionChanges == true) || (disposal_req.fl_SuggestionChanges == false))) { #region "kirim email ke approval" var next_approval = (from app in db.tr_disposal_approval where (app.approval_date == null && app.fl_active == true && app.deleted_date == null) && app.request_id == disposal_req.request_id orderby app.approval_id ascending join a in db.ms_employee on app.approval_employee_id equals a.employee_id where a.fl_active == true && a.deleted_date == null join b in db.ms_user on a.employee_id equals b.employee_id where b.fl_active == true && b.deleted_date == null select new disposalViewModel { approval_id = app.approval_id, ms_employee = a, ms_user = b }).FirstOrDefault <disposalViewModel>(); if (next_approval != null) { sy_email_log sy_email_log = new sy_email_log(); sy_email_log.elog_to = next_approval.ms_employee.employee_email; sy_email_log.elog_subject = string.Format("Asset Disposal Need Approval"); sy_email_log.elog_template = "EMAIL_TEMPLATE_04"; #region "body mail" var _bodymail = app_setting.APPLICATION_SETTING.Where(c => c.app_key.Contains("EMAIL_TEMPLATE_04")); string strBodyMail = _bodymail.FirstOrDefault().app_value; strBodyMail = strBodyMail.Replace("[to]", next_approval.ms_employee.employee_name); strBodyMail = strBodyMail.Replace("[action]", "Dispose"); strBodyMail = strBodyMail.Replace("[assetnumber]", disposal_req.asset_number); strBodyMail = strBodyMail.Replace("[aseetname]", disposal_req.asset_name); strBodyMail = strBodyMail.Replace("[assetlocation]", disposal_req.location_name); strBodyMail = strBodyMail.Replace("[department]", disposal_req.department_name); //token untuk link approval di email string token = string.Format("DisposalApproval|Approval/{0}|{1}|{2}|{3}", next_approval.approval_id, next_approval.ms_user.user_name, UserProfile.company_id, UserProfile.asset_reg_location_id); token = CryptorHelper.Encrypt(token, "MD5", true).Replace("+", "plus").Replace("=", "equal"); string linkapp = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~/Account/Login?ReturnUrl=%2f&token=" + token)); string strImg = string.Format("http://{0}/Content/EmailImage/button_approval_disposal.png", Request.Url.Authority); linkapp = string.Format(@"<a href={0}><img src=""{1}"" alt=""click for approval""/></a>", linkapp, strImg); strBodyMail = strBodyMail.Replace("[link]", linkapp); sy_email_log.elog_body = strBodyMail; #endregion 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(); } #endregion #region "Save Sy_Message_notification ke approval" sy_message_notification msg = new sy_message_notification(); msg.notif_group = "BALOON_RECEIPT_04"; msg.notify_user = next_approval.ms_user.user_name; msg.notify_ip = next_approval.ms_employee.ip_address; msg.notify_message = "Ada permintaan approval untuk Asset disposal."; msg.fl_active = true; msg.created_date = DateTime.Now; msg.created_by = UserProfile.UserId; msg.fl_shown = 0; db.sy_message_notification.Add(msg); db.SaveChanges(); #endregion } else { #region "Save Update Process Disposal" ms_disposal_type suggestion = db.ms_disposal_type.Find(disposal_req.approval_suggestion_id); tr_disposal_announcement disposalproses = new tr_disposal_announcement(); disposalproses.request_id = disposal_req.request_id; disposalproses.approval_disposal_type_id = disposal_req.approval_suggestion_id; if (disposal_req.approval_suggestion_id != 3) { disposalproses.fl_announcement_status = true; } else { disposalproses.fl_remove_asset = true; disposalproses.remove_asset_dept_id = 5; } disposalproses.fl_active = true; disposalproses.created_date = DateTime.Now; disposalproses.created_by = UserProfile.UserId; disposalproses.updated_date = DateTime.Now; disposalproses.updated_by = UserProfile.UserId; disposalproses.deleted_date = null; disposalproses.deleted_by = null; disposalproses.org_id = UserProfile.OrgId; disposalproses = db.tr_disposal_announcement.Add(disposalproses); db.SaveChanges(); #endregion #region "kirim email ke PIC Process Disposal" string emailsetting = string.Empty; string to_name = string.Empty; switch (disposal_req.approval_suggestion_id) { //resale => procurement case 1: emailsetting = "EMAIL_TO_DISPOSAL_PROCUREMENT"; to_name = "Department Procurement"; break; //donation => CSR case 2: emailsetting = "EMAIL_TO_DISPOSAL_CSR"; to_name = "Department CSR"; break; //destroy => Acounting case 3: emailsetting = "EMAIL_TO_DISPOSAL_ACCOUNTING"; to_name = "Department Accounting"; break; } var _emailto = app_setting.APPLICATION_SETTING.Where(c => c.app_key.Contains(emailsetting)); sy_email_log sy_email_log = new sy_email_log(); sy_email_log.elog_to = _emailto.FirstOrDefault().app_value; sy_email_log.elog_subject = string.Format("Asset Disposal Need Follow Up ({0})", suggestion.disposal_type_name); sy_email_log.elog_template = "EMAIL_TEMPLATE_05"; #region "body mail" var _bodymail = app_setting.APPLICATION_SETTING.Where(c => c.app_key.Contains("EMAIL_TEMPLATE_05")); string strBodyMail = _bodymail.FirstOrDefault().app_value; strBodyMail = strBodyMail.Replace("[to]", to_name); strBodyMail = strBodyMail.Replace("[assetnumber]", disposal_req.asset_number); strBodyMail = strBodyMail.Replace("[aseetname]", disposal_req.asset_name); strBodyMail = strBodyMail.Replace("[assetlocation]", disposal_req.location_name); strBodyMail = strBodyMail.Replace("[department]", disposal_req.department_name); strBodyMail = strBodyMail.Replace("[suggestion]", suggestion.disposal_type_name); strBodyMail = strBodyMail.Replace("[freetext]", ""); string linkapp = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~/Account/Login?ReturnUrl=%2f")); string strImg = string.Format("http://{0}/Content/EmailImage/button_asmin.png", Request.Url.Authority); linkapp = string.Format(@"<a href={0}><img src=""{1}"" alt=""click for process""/></a>", linkapp, strImg); strBodyMail = strBodyMail.Replace("[link]", linkapp); sy_email_log.elog_body = strBodyMail; #endregion 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(); #endregion } } transaction.Commit(); ViewBag.ResultMessage = "Update table successfully."; return(RedirectToAction("Index")); } catch (Exception) { // roll back all database operations, if any thing goes wrong transaction.Rollback(); ViewBag.ResultMessage = "Error occured, records rolledback."; } } } disposal_req = DataDisposalView(disposal_req.request_id, disposal_req); return(View(disposal_req)); }