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 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)); }
// GET: user/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ms_user ms_user = db.ms_user.Find(id); if (ms_user == null) { return(HttpNotFound()); } user_accountViewModel usr_acc = new user_accountViewModel() { fl_active = ms_user.fl_active, user_id = ms_user.user_id, user_name = ms_user.user_name, user_password = ms_user.user_password, user_type_id = ms_user.user_type_id, employee_id = ms_user.employee_id, employee_nik = ms_user.ms_employee.employee_nik, employee_name = ms_user.ms_employee.employee_name, employee_email = ms_user.ms_employee.employee_email, }; return(View(usr_acc)); }
public JsonResult Cruduser_account() { if (UserProfile.UserId != 0) { if (Request.Form["oper"] == "del") { //for delete process string ids = Request.Form["id"]; int id = Convert.ToInt32(ids); ms_user ms_user = db.ms_user.Find(id); ms_user.fl_active = false; ms_user.deleted_by = UserProfile.UserId; ms_user.deleted_date = DateTime.Now; db.Entry(ms_user).State = EntityState.Modified; db.SaveChanges(); return(Json("Delete", JsonRequestBehavior.AllowGet)); } else { return(Json("Error", JsonRequestBehavior.AllowGet)); } } else { return(Json("Session", JsonRequestBehavior.AllowGet)); } }
public ActionResult DeleteConfirmed(int id) { ms_user ms_user = db.ms_user.Find(id); db.ms_user.Remove(ms_user); db.SaveChanges(); return(RedirectToAction("Index")); }
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)); }
////GET: user/Details/5 //public ActionResult Details(int? id) //{ // if (id == null) // { // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); // } // ms_user ms_user = db.ms_user.Find(id); // if (ms_user == null) // { // return HttpNotFound(); // } // return View(ms_user); //} public ActionResult ModalFrm(int?id = 0) { user_accountViewModel usr_acc = null; int user_id = (int)id; ms_user ms_user = db.ms_user.Find(user_id); if (ms_user == null) { usr_acc = new user_accountViewModel() { fl_active = true, rec_isactive = "Yes", user_id = 0, user_type_id = 0, employee_id = 0 }; } else { usr_acc = new user_accountViewModel() { fl_active = true, rec_isactive = "Yes", user_id = ms_user.user_id, user_name = ms_user.user_name, user_password = App_Helpers.CryptorHelper.Decrypt(ms_user.user_password, "MD5", true), user_type_id = ms_user.user_type_id, user_type_name = ms_user.ms_user_type.user_type_name, employee_id = ms_user.ms_employee.employee_id, employee_nik = ms_user.ms_employee.employee_nik, employee_name = ms_user.ms_employee.employee_name, employee_email = ms_user.ms_employee.employee_email }; } List <SelectListItem> first = new List <SelectListItem> { new SelectListItem { Text = "- [Not Set] -", Value = "0", Selected = true } }; usr_acc.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); usr_acc.FormMode = (user_id > 0) ? EnumFormModeKey.Form_Edit : EnumFormModeKey.Form_New; return(PartialView(usr_acc)); }
public ActionResult Validate(AccountLoginViewModel user, string ReturnUrl) { string _controller = "home"; user.ReturnUrl = ReturnUrl; if (!String.IsNullOrWhiteSpace(user.UserName)) { ms_user _user = null; if (IsValidAdmin(user)) { FormsAuthentication.SetAuthCookie(user.UserName, true); _user = new ms_user() { user_id = 99999, user_name = user.UserName, user_password = user.Password }; UserProfile.UserId = _user.user_id; UserProfile.UserName = _user.user_name; UserProfile.UserFullName = "System Admin"; UserProfile.CompanyName = "SYS"; } else if (IsValidUser(user)) { FormsAuthentication.SetAuthCookie(user.UserName, true); _user = GetUserByUsername(user.UserName); UserProfile.UserId = _user.user_id; UserProfile.UserName = _user.user_name; UserProfile.UserFullName = _user.ms_employee.employee_name; UserProfile.CompanyName = "ABB"; // _user.ms_employee.ms_employee_detail.FirstOrDefault().ms_asmin_company.company_name; UserProfile.Employee = null; } ViewData["user"] = _user; if (ReturnUrl != null) { return(Redirect(ReturnUrl)); } //Request.IsAuthenticated; //if (!Request.IsAuthenticated) //{ // //return RedirectToAction("index", "home"); //} } else { _controller = "login"; //return RedirectToAction("index", "login"); } return(RedirectToAction("Index", _controller)); }
// GET: user/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ms_user ms_user = db.ms_user.Find(id); if (ms_user == null) { return(HttpNotFound()); } return(View(ms_user)); }
public ActionResult DeleteConfirmed(int id) { //ms_user ms_user = db.ms_user.Find(id); //db.ms_user.Remove(ms_user); //db.SaveChanges(); ms_user ms_user = db.ms_user.Find(id); ms_user.fl_active = false; ms_user.deleted_by = UserProfile.UserId; ms_user.deleted_date = DateTime.Now; db.Entry(ms_user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: user/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ms_user ms_user = db.ms_user.Find(id); if (ms_user == null) { return(HttpNotFound()); } ViewBag.employee_id = new SelectList(db.ms_employee, "employee_id", "employee_nik", ms_user.employee_id); return(View(ms_user)); }
private bool IsValidUser(AccountLoginViewModel user) { bool booValid = false; ms_user _user = GetUserByUsername(user.UserName); //ambil dari db if (_user != null) { booValid = user.Password.Equals(_user.user_password); } else //user not found { booValid = false; } return(booValid); }
// GET: user/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ms_user ms_user = db.ms_user.Find(id); if (ms_user == null) { return(HttpNotFound()); } //return View(ms_user); ms_user.fl_active = false; ms_user.deleted_by = UserProfile.UserId; ms_user.deleted_date = DateTime.Now; db.Entry(ms_user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "user_id,user_name,user_password,user_type_id,employee_id,fl_active")] user_accountViewModel user_acc) { if (ModelState.IsValid) { ms_user ms_user = db.ms_user.Find(user_acc.user_id); ms_user.user_name = user_acc.user_name; if (!string.IsNullOrWhiteSpace(user_acc.user_password)) { ms_user.user_password = App_Helpers.CryptorHelper.Encrypt(user_acc.user_password, "MD5", true); } ms_user.user_type_id = user_acc.user_type_id; ms_user.fl_active = true; ms_user.updated_by = UserProfile.UserId; ms_user.updated_date = DateTime.Now; ms_user.deleted_by = null; ms_user.deleted_date = null; ms_employee emp = db.ms_employee.Find(user_acc.employee_id); if (emp != null) { ms_user.employee_id = emp.employee_id; 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; } db.Entry(ms_user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user_acc)); }
public ActionResult Create([Bind(Include = "asset_id, asset_number,asset_name, location_id, location_name, department_name, request_description")] disposalViewModel disposal_req) { if (Request.Files.Count > 0) { var fileexist = Request.Files["asset_img_address"]; if (fileexist == null || fileexist.ContentLength == 0) { ModelState.AddModelError("asset_img_address", "Asset image is mandatory."); } } //input data request disposal with transaction if (ModelState.IsValid) { //Int32 z = Convert.ToInt32("a"); using (var transaction = db.Database.BeginTransaction()) { try { #region "Save Request Disposal" tr_disposal_request disposal_request = new tr_disposal_request(); disposal_request.disposal_number = DisposalNumberNew(disposal_req.asset_id); disposal_request.asset_id = disposal_req.asset_id; disposal_request.request_date = DateTime.Now; disposal_request.request_description = disposal_req.request_description; disposal_request.request_location_id = disposal_req.location_id; disposal_request.request_dept_id = UserProfile.department_id; disposal_request.request_emp_id = UserProfile.employee_id; disposal_request.request_status_id = 1; disposal_request.fl_active = true; disposal_request.created_date = DateTime.Now; disposal_request.created_by = UserProfile.UserId; disposal_request.updated_date = DateTime.Now; disposal_request.update_by = UserProfile.UserId; disposal_request.deleted_date = null; disposal_request.deleted_by = null; disposal_request.org_id = UserProfile.OrgId; disposal_request = db.tr_disposal_request.Add(disposal_request); db.SaveChanges(); //Save Approval Dept. Head var _qry = (from sa in db.sy_ref_approval_level where sa.asset_reg_location_id == disposal_req.location_id && sa.job_level_id == 2 join a in db.ms_job_level on sa.job_level_id equals a.job_level_id where (a.fl_active == true && a.deleted_date == null) join b in db.ms_employee_detail on a.job_level_id equals b.job_level_id where (b.fl_active == true && b.deleted_date == null && b.department_id == UserProfile.department_id && b.company_id == UserProfile.company_id) join c in db.ms_employee on b.employee_id equals c.employee_id where c.fl_active == true && c.deleted_date == null orderby sa.order_no ascending select new disposalViewModel() { department_id = b.department_id, employee_id = b.employee_id, job_level_id = a.job_level_id, employee_email = c.employee_email, employee_name = c.employee_name, ip_address = c.ip_address }).ToList <disposalViewModel>(); int count = 1; int approval_id = 0; if (_qry != null) { foreach (disposalViewModel refApproval in _qry) { tr_disposal_approval disposal_approval = new tr_disposal_approval(); disposal_approval.request_id = disposal_request.request_id; disposal_approval.approval_date = null; disposal_approval.approval_dept_id = refApproval.department_id; disposal_approval.approval_employee_id = refApproval.employee_id; disposal_approval.approval_level_id = refApproval.job_level_id; disposal_approval.approval_status_id = 1;//waiting approval disposal_approval.fl_active = true; disposal_approval.created_date = DateTime.Now; disposal_approval.created_by = UserProfile.UserId; disposal_approval.updated_date = DateTime.Now; disposal_approval.updated_by = UserProfile.UserId; disposal_approval.deleted_date = null; disposal_approval.deteled_by = null; disposal_approval.org_id = UserProfile.OrgId; disposal_approval = db.tr_disposal_approval.Add(disposal_approval); db.SaveChanges(); if (count == 1) { //untuk kebutuhan link email count++; approval_id = disposal_approval.approval_id; } } } //Save Approval Dept. Head var _qry_ktt = (from sa in db.sy_ref_approval_level where sa.asset_reg_location_id == disposal_req.location_id && sa.job_level_id == 3 join a in db.ms_job_level on sa.job_level_id equals a.job_level_id where (a.fl_active == true && a.deleted_date == null) join b in db.ms_employee_detail on a.job_level_id equals b.job_level_id where (b.fl_active == true && b.deleted_date == null && b.company_id == UserProfile.company_id) join c in db.ms_employee on b.employee_id equals c.employee_id where c.fl_active == true && c.deleted_date == null orderby sa.order_no ascending select new disposalViewModel() { department_id = b.department_id, employee_id = b.employee_id, job_level_id = a.job_level_id, employee_email = c.employee_email, employee_name = c.employee_name, ip_address = c.ip_address }).ToList <disposalViewModel>(); int count_ktt = 1; int approval_id_ktt = 0; if (_qry_ktt != null) { foreach (disposalViewModel refApproval in _qry_ktt) { tr_disposal_approval disposal_approval = new tr_disposal_approval(); disposal_approval.request_id = disposal_request.request_id; disposal_approval.approval_date = null; disposal_approval.approval_dept_id = refApproval.department_id; disposal_approval.approval_employee_id = refApproval.employee_id; disposal_approval.approval_level_id = refApproval.job_level_id; disposal_approval.approval_status_id = 1;//waiting approval disposal_approval.fl_active = true; disposal_approval.created_date = DateTime.Now; disposal_approval.created_by = UserProfile.UserId; disposal_approval.updated_date = DateTime.Now; disposal_approval.updated_by = UserProfile.UserId; disposal_approval.deleted_date = null; disposal_approval.deteled_by = null; disposal_approval.org_id = UserProfile.OrgId; disposal_approval = db.tr_disposal_approval.Add(disposal_approval); db.SaveChanges(); if (count_ktt == 1) { //untuk kebutuhan link email count_ktt++; approval_id_ktt = disposal_approval.approval_id; } } } //Approval BOD berdasarkan data ms_department >> employee_bod_id ms_department dept = db.ms_department.Find(UserProfile.department_id); if (dept != null) { tr_disposal_approval disposal_approval = new tr_disposal_approval(); disposal_approval.request_id = disposal_request.request_id; disposal_approval.approval_date = null; disposal_approval.approval_dept_id = dept.department_id; disposal_approval.approval_employee_id = dept.employee_bod_id; disposal_approval.approval_level_id = 9; disposal_approval.approval_status_id = 1;//waiting approval disposal_approval.fl_active = true; disposal_approval.created_date = DateTime.Now; disposal_approval.created_by = UserProfile.UserId; disposal_approval.updated_date = DateTime.Now; disposal_approval.updated_by = UserProfile.UserId; disposal_approval.deleted_date = null; disposal_approval.deteled_by = null; disposal_approval.org_id = UserProfile.OrgId; disposal_approval = db.tr_disposal_approval.Add(disposal_approval); db.SaveChanges(); } if (Request.Files.Count > 0) { //var file = Request.Files[0]; app_root_path = Server.MapPath("~/"); if (string.IsNullOrWhiteSpace(base_image_path)) { base_image_path = asset_registrationViewModel.path_file_disposal; } string img_path = Server.MapPath(base_image_path); if (!Directory.Exists(img_path)) { Directory.CreateDirectory(img_path); } var file = Request.Files["asset_img_address"]; if (file != null && file.ContentLength > 0) { var fileName = "asset" + disposal_req.asset_id.ToString() + "_" + Path.GetFileName(file.FileName); var path = Path.Combine(img_path, fileName); file.SaveAs(path); tr_disposal_image _ass_img = new tr_disposal_image() { request_id = disposal_request.request_id, asset_id = Convert.ToInt32(disposal_req.asset_id), asset_img_address = fileName, }; db.tr_disposal_image.Add(_ass_img); db.SaveChanges(); } } #endregion #region "kirim email ke approval level 1" sy_email_log sy_email_log = new sy_email_log(); sy_email_log.elog_to = _qry.FirstOrDefault().employee_email; sy_email_log.elog_subject = string.Format("Asset Disposal Need Approval"); sy_email_log.elog_template = "EMAIL_TEMPLATE_04"; 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]", _qry.FirstOrDefault().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); int empid = Convert.ToInt32(_qry.FirstOrDefault().employee_id); ms_user msuser = (from m in db.ms_user where m.employee_id == empid select m).FirstOrDefault(); //token untuk link approval di email string token = string.Format("DisposalApproval|Approval/{0}|{1}|{2}|{3}", approval_id, msuser.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; 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" sy_message_notification msg = new sy_message_notification(); msg.notif_group = "BALOON_RECEIPT_04"; msg.notify_user = msuser.user_name; msg.notify_ip = _qry.FirstOrDefault().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 transaction.Commit(); ViewBag.ResultMessage = "Record inserted into table successfully."; return(RedirectToAction("Index")); } catch (Exception ex) { // roll back all database operations, if any thing goes wrong transaction.Rollback(); string msgErr = string.Format("An unknown error has occurred , Please contact your system administrator. {0}", ex.Message); if (ex.InnerException != null) { msgErr += string.Format(" Inner Exception: {0}", ex.InnerException.Message); } ModelState.AddModelError("", msgErr); } } } return(View(disposal_req)); }
public ActionResult Approval([Bind(Include = "request_id, asset_id, approval_id, fl_approval, approval_noted, asset_number,asset_name, location_name, department_name, employee_name, transfer_to_location_name, transfer_to_dept_name, transfer_to_emp_name, transfer_to_location_id, transfer_to_dept_id, transfer_to_emp_id")] AssetMutationViewModel mutation_req) { if (mutation_req.fl_approval != null) { if (mutation_req.fl_approval == true) { //if (mutation_req.approval_suggestion_id == null || mutation_req.approval_suggestion_id == 0) // ModelState.AddModelError("approval_suggestion_id", "Suggestion is Mandatory."); } } else if (mutation_req.approval_noted == null || mutation_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 Asset Mutation" tr_mutation_request mutation_request = db.tr_mutation_request.Find(mutation_req.request_id); mutation_request.fl_approval = mutation_req.fl_approval; if (mutation_req.fl_approval == true) { var doneapp = (from app in db.tr_mutation_approval where (app.approval_date == null && app.fl_active == true && app.deleted_date == null && app.request_id == mutation_req.request_id) select app).ToList(); if (doneapp.Count == 1) { mutation_request.request_status = 5;//complete iscomplete = true; tr_mutation_process tr = new tr_mutation_process(); tr.request_id = mutation_req.request_id; tr.org_id = UserProfile.OrgId; tr.fl_active = true; tr = db.tr_mutation_process.Add(tr); db.SaveChanges(); } else { mutation_request.request_status = 2;//approve } } else { mutation_request.request_status = 3; //reject } mutation_request.approval_date = DateTime.Now; mutation_request.updated_date = DateTime.Now; mutation_request.updated_by = UserProfile.UserId; mutation_request.deleted_date = null; mutation_request.deleted_by = null; db.Entry(mutation_request).State = EntityState.Modified; db.SaveChanges(); #endregion #region "Save update Approval Mutation" tr_mutation_approval mutation_approval = db.tr_mutation_approval.Find(mutation_req.approval_id); if (mutation_req.fl_approval == true) { mutation_approval.approval_status_id = 2;//approve } else { mutation_approval.approval_status_id = 3; //reject mutation_approval.approval_noted = mutation_req.approval_noted; } mutation_approval.approval_date = DateTime.Now; //mutation_approval.approval_location_id = UserProfile.location_id; --> location_id bukan dari login mutation_approval.updated_date = DateTime.Now; mutation_approval.updated_by = UserProfile.UserId; mutation_approval.deleted_date = null; mutation_approval.deteled_by = null; db.Entry(mutation_approval).State = EntityState.Modified; db.SaveChanges(); #endregion if (mutation_req.fl_approval == true) { if (!iscomplete) { #region "kirim email ke approval" var next_approval = (from app in db.tr_mutation_approval where (app.approval_date == null && app.fl_active == true && app.deleted_date == null) && app.request_id == mutation_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 select a).FirstOrDefault <ms_employee>(); if (next_approval != null) { sy_email_log sy_email_log = new sy_email_log(); sy_email_log.elog_to = next_approval.employee_email; sy_email_log.elog_subject = string.Format("Asset Mutation Need Approval"); sy_email_log.elog_template = "EMAIL_TEMPLATE_02"; #region "body mail" var _bodymail = app_setting.APPLICATION_SETTING.Where(c => c.app_key.Contains("EMAIL_TEMPLATE_02")); string strBodyMail = _bodymail.FirstOrDefault().app_value; strBodyMail = strBodyMail.Replace("[to]", next_approval.employee_name); strBodyMail = strBodyMail.Replace("[assetnumber]", mutation_req.asset_number); strBodyMail = strBodyMail.Replace("[assetname]", mutation_req.asset_name); strBodyMail = strBodyMail.Replace("[assetlocation]", mutation_req.location_name); strBodyMail = strBodyMail.Replace("[department]", mutation_req.department_name); strBodyMail = strBodyMail.Replace("[employee]", mutation_req.employee_name); //strBodyMail = strBodyMail.Replace("[link]", ""); 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" if (next_approval != null) { int empid = Convert.ToInt32(next_approval.employee_id); ms_user msuser = (from m in db.ms_user where m.employee_id == empid select m).FirstOrDefault(); sy_message_notification msg = new sy_message_notification(); msg.notif_group = "BALOON_RECEIPT_03"; msg.notify_user = msuser.user_name; msg.notify_ip = next_approval.ip_address; msg.notify_message = "Ada permintaan approval untuk asset mutasi."; 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 { //kl dh complete??? } } 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."; } } } mutation_req = DataMutationView(mutation_req.request_id, mutation_req); return(View(mutation_req)); }
public ActionResult DisposalFollowup([Bind(Include = "announcement_id, request_id, announcement_upload_address, announcement_description, asset_number, asset_name, location_name, department_name, fl_SuggestionChanges, approval_suggestion_id")] disposalViewModel disposal_prs) { tr_disposal_announcement disposal_announcement = db.tr_disposal_announcement.Find(disposal_prs.announcement_id); if (disposal_prs.fl_SuggestionChanges == null || disposal_prs.fl_SuggestionChanges == false) { if (Request.Files.Count > 0) { var file = Request.Files["announcement_upload_address"]; if (file == null || file.ContentLength == 0) { ModelState.AddModelError("announcement_upload_address", "Berita Acara is Mandatory."); } } } else { if (disposal_prs.approval_suggestion_id == null || disposal_prs.approval_suggestion_id == 0) { ModelState.AddModelError("approval_suggestion_id", "Suggestion is Mandatory."); } } //update disposal request and approval data with transaction if (ModelState.IsValid) { using (var transaction = db.Database.BeginTransaction()) { try { if (disposal_prs.fl_SuggestionChanges == null || disposal_prs.fl_SuggestionChanges == false) { //Process Normal #region "Save update Disposal Announcement" if (Request.Files.Count > 0) { //var file = Request.Files[0]; app_root_path = Server.MapPath("~/"); if (string.IsNullOrWhiteSpace(base_file_path)) { base_file_path = asset_registrationViewModel.path_file_disposal; } string _file = Server.MapPath(base_file_path); if (!Directory.Exists(_file)) { Directory.CreateDirectory(_file); } var file = Request.Files["announcement_upload_address"]; if (file != null && file.ContentLength > 0) { var fileName = "dispose_precurement_" + disposal_prs.request_id.ToString() + "_" + Path.GetFileName(file.FileName); var path = Path.Combine(_file, fileName); file.SaveAs(path); disposal_announcement.announcement_upload_address = fileName; disposal_announcement.announcement_description = disposal_prs.announcement_description; disposal_announcement.announcement_date = DateTime.Now; disposal_announcement.announcement_emp_id = UserProfile.employee_id; disposal_announcement.fl_remove_asset = true; disposal_announcement.remove_asset_dept_id = 5; } } disposal_announcement.updated_date = DateTime.Now; disposal_announcement.updated_by = UserProfile.UserId; disposal_announcement.deleted_date = null; disposal_announcement.deleted_by = null; db.Entry(disposal_announcement).State = EntityState.Modified; db.SaveChanges(); #endregion #region "kirim email ke PIC Process Disposal" string emailsetting = string.Empty; string to_name = string.Empty; string freetext = string.Empty; emailsetting = "EMAIL_TO_DISPOSAL_ACCOUNTING"; to_name = "Department Accounting"; freetext = "Dokumen <strong>Berita Acara</strong> sudah tersedia. Asset menunggu tindak lanjut (<strong>Dispose</strong>) oleh Accounting Department."; 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 (Donation)"); 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_prs.asset_number); strBodyMail = strBodyMail.Replace("[aseetname]", disposal_prs.asset_name); strBodyMail = strBodyMail.Replace("[assetlocation]", disposal_prs.location_name); strBodyMail = strBodyMail.Replace("[department]", disposal_prs.department_name); strBodyMail = strBodyMail.Replace("[suggestion]", "Donation"); strBodyMail = strBodyMail.Replace("[freetext]", 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 } else if (disposal_prs.fl_SuggestionChanges == true) { #region "Update Data Announcement" //update flag active = false disposal_announcement.fl_suggestion_changes = true; disposal_announcement.fl_active = false; disposal_announcement.updated_date = DateTime.Now; disposal_announcement.updated_by = UserProfile.UserId; disposal_announcement.deleted_date = null; disposal_announcement.deleted_by = null; db.Entry(disposal_announcement).State = EntityState.Modified; db.SaveChanges(); #endregion #region "Save create disposal_approval" var refApproval = (from a in db.ms_job_level where (a.fl_active == true && a.deleted_date == null && a.job_level_id == 2) join b in db.ms_employee_detail on a.job_level_id equals b.job_level_id where (b.fl_active == true && b.deleted_date == null && b.department_id == 10 && b.company_id == UserProfile.company_id) join c in db.ms_employee on b.employee_id equals c.employee_id where c.fl_active == true && c.deleted_date == null select new disposalViewModel() { department_id = b.department_id, employee_id = b.employee_id, job_level_id = a.job_level_id, employee_email = c.employee_email, employee_name = c.employee_name }).First <disposalViewModel>(); //approval disposal changes level 1 tr_disposal_approval disposal_approval = new tr_disposal_approval(); disposal_approval.request_id = disposal_prs.request_id; disposal_approval.approval_date = null; disposal_approval.approval_dept_id = refApproval.department_id; disposal_approval.approval_employee_id = refApproval.employee_id; disposal_approval.approval_level_id = refApproval.job_level_id; disposal_approval.approval_status_id = 1;//waiting approval disposal_approval.approval_suggestion_id = disposal_prs.approval_suggestion_id; disposal_approval.fl_active = true; disposal_approval.created_date = DateTime.Now; disposal_approval.created_by = UserProfile.UserId; disposal_approval.updated_date = DateTime.Now; disposal_approval.updated_by = UserProfile.UserId; disposal_approval.deleted_date = null; disposal_approval.deteled_by = null; disposal_approval.org_id = UserProfile.OrgId; disposal_approval = db.tr_disposal_approval.Add(disposal_approval); db.SaveChanges(); int approval_id = disposal_approval.approval_id; //approval disposal changes level 2 tr_disposal_request disposalrequest = db.tr_disposal_request.Find(disposal_prs.request_id); tr_asset_registration assetreg = db.tr_asset_registration.Find(disposalrequest.asset_id); if (assetreg.location_id != 1) { var refApproval2 = (from a in db.ms_job_level where (a.fl_active == true && a.deleted_date == null && a.job_level_id == 3) join b in db.ms_employee_detail on a.job_level_id equals b.job_level_id where (b.fl_active == true && b.deleted_date == null && b.department_id == disposalrequest.request_dept_id && b.company_id == assetreg.company_id) join c in db.ms_employee on b.employee_id equals c.employee_id where c.fl_active == true && c.deleted_date == null select new disposalViewModel() { department_id = b.department_id, employee_id = b.employee_id, job_level_id = a.job_level_id, employee_email = c.employee_email, employee_name = c.employee_name }).First <disposalViewModel>(); disposal_approval = new tr_disposal_approval(); disposal_approval.request_id = disposal_prs.request_id; disposal_approval.approval_date = null; disposal_approval.approval_dept_id = refApproval2.department_id; disposal_approval.approval_employee_id = refApproval2.employee_id; disposal_approval.approval_level_id = refApproval2.job_level_id; disposal_approval.approval_status_id = 1;//waiting approval disposal_approval.approval_suggestion_id = disposal_prs.approval_suggestion_id; disposal_approval.fl_active = true; disposal_approval.created_date = DateTime.Now; disposal_approval.created_by = UserProfile.UserId; disposal_approval.updated_date = DateTime.Now; disposal_approval.updated_by = UserProfile.UserId; disposal_approval.deleted_date = null; disposal_approval.deteled_by = null; disposal_approval.org_id = UserProfile.OrgId; disposal_approval = db.tr_disposal_approval.Add(disposal_approval); db.SaveChanges(); } #endregion #region "Kirim email ke Procurement Head" sy_email_log sy_email_log = new sy_email_log(); sy_email_log.elog_to = refApproval.employee_email; sy_email_log.elog_subject = string.Format("Asset Disposal Changes Need Approval"); sy_email_log.elog_template = "EMAIL_TEMPLATE_04"; 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]", refApproval.employee_name); strBodyMail = strBodyMail.Replace("[action]", "Disposal Changes"); strBodyMail = strBodyMail.Replace("[assetnumber]", disposal_prs.asset_number); strBodyMail = strBodyMail.Replace("[aseetname]", disposal_prs.asset_name); strBodyMail = strBodyMail.Replace("[assetlocation]", disposal_prs.location_name); strBodyMail = strBodyMail.Replace("[department]", disposal_prs.department_name); int empid = Convert.ToInt32(refApproval.employee_id); ms_user msuser = (from m in db.ms_user where m.employee_id == empid select m).FirstOrDefault(); //token untuk link approval di email string token = string.Format("DisposalApproval|Approval/{0}|{1}|{2}|{3}", approval_id, msuser.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; 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_prs = DataDisposalView(disposal_prs.request_id, disposal_prs); return(View(disposal_prs)); }
public ActionResult request([Bind(Include = "asset_id, asset_number, asset_name, current_location_id, location_name, current_department_id, department_name, current_employee_id, employee_name, transfer_to_location_id, transfer_to_dept_id, transfer_to_emp_id, asset_original_value")] AssetMutationViewModel mutation_req) { //Cek apakah disposal sudah di proses sebelumnya (kecuali reject) var _MutationExist = (from dr in db.tr_mutation_request where (dr.fl_active == true && dr.deleted_date == null) && dr.asset_id == mutation_req.asset_id select dr).ToList <tr_mutation_request>(); if (_MutationExist.Count > 0) { ModelState.AddModelError("asset_number", "Asset Already Exists in Disposal Request Data."); } //input data request disposal with transaction if (ModelState.IsValid) { using (var transaction = db.Database.BeginTransaction()) { try { //Save Request Disposal tr_mutation_request mutation_request = new tr_mutation_request(); mutation_request.request_code = MutationNumberNew(mutation_req.asset_id); mutation_request.asset_id = mutation_req.asset_id; mutation_request.request_date = DateTime.Now; //mutation_request.request_location_id = UserProfile.location_id; //mutation_request.request_dept_id = UserProfile.department_id; //mutation_request.request_emp_id = UserProfile.employee_id; mutation_request.request_location_id = mutation_req.current_location_id; mutation_request.request_dept_id = mutation_req.current_department_id; mutation_request.request_emp_id = mutation_req.current_employee_id; mutation_request.request_status = 1; mutation_request.transfer_to_location_id = mutation_req.transfer_to_location_id; mutation_request.transfer_to_dept_id = mutation_req.transfer_to_dept_id; mutation_request.transfer_to_emp_id = mutation_req.transfer_to_emp_id; mutation_request.fl_active = true; mutation_request.created_date = DateTime.Now; mutation_request.created_by = UserProfile.UserId; mutation_request.updated_date = DateTime.Now; mutation_request.updated_by = UserProfile.UserId; mutation_request.deleted_date = null; mutation_request.deleted_by = null; mutation_request.org_id = UserProfile.OrgId; mutation_request = db.tr_mutation_request.Add(mutation_request); db.SaveChanges(); var x = UserProfile.OrgId; //Save Approval List Mutation Untuk Dept Head //Hendy 22 Feb 2020 var _qry = (from sa in db.sy_ref_approval_level where sa.asset_reg_location_id == mutation_req.current_location_id && sa.job_level_id == 2 join a in db.ms_job_level on sa.job_level_id equals a.job_level_id where (a.fl_active == true && a.deleted_date == null) join b in db.ms_employee_detail on a.job_level_id equals b.job_level_id where (b.fl_active == true && b.deleted_date == null //&& b.department_id == UserProfile.department_id && b.org_id == UserProfile.OrgId) && b.department_id == mutation_req.current_department_id && b.company_id == UserProfile.company_id) join c in db.ms_employee on b.employee_id equals c.employee_id orderby sa.order_no ascending select new AssetMutationViewModel() { //request_location_id = b.loca request_dept_id = b.department_id, request_emp_id = b.employee_id, request_level_id = a.job_level_id, current_employee_id = c.employee_id, employee_email = c.employee_email, employee_name = c.employee_name, ip_address = c.ip_address }).ToList <AssetMutationViewModel>(); if (_qry != null) { foreach (AssetMutationViewModel refApproval in _qry) { tr_mutation_approval mutation_approval = new tr_mutation_approval(); mutation_approval.request_id = mutation_request.request_id; mutation_approval.approval_date = null; mutation_approval.approval_location_id = /*refApproval.request_location_id*/ 0; mutation_approval.approval_dept_id = refApproval.request_dept_id; mutation_approval.approval_employee_id = refApproval.request_emp_id; mutation_approval.approval_level_id = refApproval.request_level_id; mutation_approval.approval_status_id = 1;//waiting approval mutation_approval.approval_noted = ""; mutation_approval.fl_active = true; mutation_approval.created_date = DateTime.Now; mutation_approval.created_by = UserProfile.UserId; mutation_approval.updated_date = DateTime.Now; mutation_approval.updated_by = UserProfile.UserId; mutation_approval.deleted_date = null; mutation_approval.deteled_by = null; mutation_approval.org_id = UserProfile.OrgId; mutation_approval = db.tr_mutation_approval.Add(mutation_approval); db.SaveChanges(); } } //Check KTT //check range approval decimal ktt_asset_value = Convert.ToDecimal(mutation_req.asset_original_value); bool isKTTApproval = false; ms_approval_range range_ktt = db.ms_approval_range.Where(r => r.range_code == "M_lv2").FirstOrDefault(); if (range_ktt != null) { isKTTApproval = (range_ktt.range_min <= ktt_asset_value); } if (isKTTApproval) { var x_ktt = UserProfile.OrgId; //Save Approval List Mutation Untuk Dept Head //Hendy 22 Feb 2020 var _qry_ktt = (from sa in db.sy_ref_approval_level where sa.asset_reg_location_id == mutation_req.current_location_id && sa.job_level_id == 3 join a in db.ms_job_level on sa.job_level_id equals a.job_level_id where (a.fl_active == true && a.deleted_date == null) join b in db.ms_employee_detail on a.job_level_id equals b.job_level_id where (b.fl_active == true && b.deleted_date == null) && b.company_id == UserProfile.company_id join c in db.ms_employee on b.employee_id equals c.employee_id where c.employee_id == UserProfile.employee_id orderby sa.order_no ascending select new AssetMutationViewModel() { //request_location_id = b.loca request_dept_id = b.department_id, request_emp_id = b.employee_id, request_level_id = a.job_level_id, current_employee_id = c.employee_id, employee_email = c.employee_email, employee_name = c.employee_name, ip_address = c.ip_address }).ToList <AssetMutationViewModel>(); if (_qry_ktt != null) { foreach (AssetMutationViewModel refApproval in _qry_ktt) { tr_mutation_approval mutation_approval = new tr_mutation_approval(); mutation_approval.request_id = mutation_request.request_id; mutation_approval.approval_date = null; mutation_approval.approval_location_id = /*refApproval.request_location_id*/ 0; mutation_approval.approval_dept_id = refApproval.request_dept_id; mutation_approval.approval_employee_id = refApproval.request_emp_id; mutation_approval.approval_level_id = refApproval.request_level_id; mutation_approval.approval_status_id = 1;//waiting approval mutation_approval.approval_noted = ""; mutation_approval.fl_active = true; mutation_approval.created_date = DateTime.Now; mutation_approval.created_by = UserProfile.UserId; mutation_approval.updated_date = DateTime.Now; mutation_approval.updated_by = UserProfile.UserId; mutation_approval.deleted_date = null; mutation_approval.deteled_by = null; mutation_approval.org_id = UserProfile.OrgId; mutation_approval = db.tr_mutation_approval.Add(mutation_approval); db.SaveChanges(); } } } decimal asset_value = Convert.ToDecimal(mutation_req.asset_original_value); bool isBODApproval = false; ms_approval_range range = db.ms_approval_range.Where(r => r.range_code == "M_BOD").FirstOrDefault(); if (range != null) { isBODApproval = (range.range_min <= asset_value); } if (isBODApproval) { //Approval BOD berdasarkan data ms_department >> employee_bod_id ms_department dept = db.ms_department.Find(UserProfile.department_id); if (dept != null) { tr_mutation_approval mutation_approval = new tr_mutation_approval(); mutation_approval.request_id = mutation_request.request_id; mutation_approval.approval_date = null; mutation_approval.approval_location_id = /*refApproval.request_location_id*/ 0; mutation_approval.approval_dept_id = dept.department_id; mutation_approval.approval_employee_id = dept.employee_bod_id; mutation_approval.approval_level_id = 9; mutation_approval.approval_status_id = 1;//waiting approval mutation_approval.approval_noted = ""; mutation_approval.fl_active = true; mutation_approval.created_date = DateTime.Now; mutation_approval.created_by = UserProfile.UserId; mutation_approval.updated_date = DateTime.Now; mutation_approval.updated_by = UserProfile.UserId; mutation_approval.deleted_date = null; mutation_approval.deteled_by = null; mutation_approval.org_id = UserProfile.company_id; mutation_approval = db.tr_mutation_approval.Add(mutation_approval); db.SaveChanges(); } } #region "kirim email ke approval level 1" sy_email_log sy_email_log = new sy_email_log(); sy_email_log.elog_to = _qry.FirstOrDefault().employee_email; sy_email_log.elog_subject = string.Format("Asset Mutation Need Approval"); sy_email_log.elog_template = "EMAIL_TEMPLATE_02"; #region "body mail" var _bodymail = app_setting.APPLICATION_SETTING.Where(c => c.app_key.Contains("EMAIL_TEMPLATE_02")); string strBodyMail = _bodymail.FirstOrDefault().app_value; strBodyMail = strBodyMail.Replace("[to]", _qry.FirstOrDefault().employee_name); strBodyMail = strBodyMail.Replace("[assetnumber]", mutation_req.asset_number); strBodyMail = strBodyMail.Replace("[assetname]", mutation_req.asset_name); strBodyMail = strBodyMail.Replace("[assetlocation]", mutation_req.location_name); strBodyMail = strBodyMail.Replace("[department]", mutation_req.department_name); strBodyMail = strBodyMail.Replace("[employee]", mutation_req.employee_name); //strBodyMail = strBodyMail.Replace("[link]", ""); 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" int empid = Convert.ToInt32(_qry.FirstOrDefault().current_employee_id); ms_user msuser = (from m in db.ms_user where m.employee_id == empid select m).FirstOrDefault(); sy_message_notification msg = new sy_message_notification(); msg.notif_group = "BALOON_RECEIPT_03"; msg.notify_user = msuser.user_name; msg.notify_ip = _qry.FirstOrDefault().ip_address; msg.notify_message = "Ada permintaan approval untuk asset mutasi."; 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 transaction.Commit(); ViewBag.ResultMessage = "Record inserted into table successfully."; return(RedirectToAction("Index")); } catch (Exception ex) { // roll back all database operations, if any thing goes wrong transaction.Rollback(); string msgErr = string.Format("Error occured, records rolledback. {0}", ex.Message); if (ex.InnerException != null) { msgErr += string.Format(" Inner Exception: {0}", ex.InnerException.Message); } ModelState.AddModelError("", msgErr); } } } #region "for dropdown Employee" //var _employeelist = from s in db.ms_disposal_type // select s; var _employeelist = db.ms_employee.Where(t => t.deleted_date == null && t.fl_active == true).Select( t => new { t.employee_id, t.employee_nik, t.employee_name }).ToList(); SelectList itemsType = new SelectList(_employeelist, "employee_id", "employee_name"); ViewBag.transfer_to_emp_id = itemsType; #endregion #region "for dropdown Department" var _departmentlist = db.ms_department.Where(t => t.deleted_date == null && t.fl_active == true).Select( t => new { t.department_id, t.department_code, t.department_name }).ToList(); SelectList itemsType2 = new SelectList(_departmentlist, "department_id", "department_name"); ViewBag.transfer_to_dept_id = itemsType2; #endregion #region "for dropdown Location" var _locationlist = db.ms_asset_location.Where(t => t.deleted_date == null && t.fl_active == true).Select( t => new { t.location_id, t.location_code, t.location_name }).ToList(); SelectList itemsType3 = new SelectList(_locationlist, "location_id", "location_name"); ViewBag.transfer_to_location_id = itemsType3; #endregion return(View(mutation_req)); }
public ActionResult Registration(AccountRegistrationViewModel registrationView) { bool statusRegistration = false; string messageRegistration = string.Empty; if (ModelState.IsValid) { // Email Verification string userName = Membership.GetUserNameByEmail(registrationView.employee_email); if (!string.IsNullOrEmpty(userName)) { ModelState.AddModelError("Warning Email", "Sorry: Email already Exists"); return(View(registrationView)); } //Save User Data using (ModelAsmRemote _db = new ModelAsmRemote()) { //var user = new User() //{ // Username = registrationView.Username, // FirstName = registrationView.FirstName, // LastName = registrationView.LastName, // Email = registrationView.Email, // Password = registrationView.Password, // ActivationCode = Guid.NewGuid(), //}; //dbContext.Users.Add(user); var emp = new ms_employee() { employee_email = registrationView.employee_email, employee_nik = registrationView.employee_nik, employee_name = registrationView.employee_name, 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 }; emp = _db.ms_employee.Add(emp); //int emp_id = emp.employee_id; var user = new ms_user() { user_name = registrationView.user_name, user_password = App_Helpers.CryptorHelper.Encrypt(registrationView.user_password, "MD5", true), employee_id = emp.employee_id, 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 }; _db.ms_user.Add(user); _db.SaveChanges(); } //Verification Email: //TIDAK usah aktifkan by email -> admin saja yanag mengaktifkan sendiri krna hrus pilih role, job title dan company //VerificationEmail(registrationView.Email, registrationView.ActivationCode.ToString()); messageRegistration = "Your account has been created successfully. ^_^"; statusRegistration = true; } else { messageRegistration = "Something Wrong!"; } ViewBag.Message = messageRegistration; ViewBag.Status = statusRegistration; return(View(registrationView)); }
public ActionResult SaveDataUserAccount([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 { #region INSERT_DATA if (user_acc.FormMode == EnumFormModeKey.Form_New) { ms_employee emp = db.ms_employee.Find(user_acc.employee_id); if (emp == null) { throw new Exception("Employee not found. Please create Employee first " + 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 = db.ms_user.Find(user_acc.user_id); if (ms_user == null) { 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); } else { ms_user.user_name = user_acc.user_name; ms_user.user_password = App_Helpers.CryptorHelper.Encrypt(user_acc.user_password, "MD5", true); ms_user.user_type_id = user_acc.user_type_id; ms_user.employee_id = user_acc.employee_id; ms_user.fl_active = user_acc.fl_active; ms_user.created_by = UserProfile.UserId; ms_user.created_date = DateTime.Now; ms_user.updated_by = UserProfile.UserId; ms_user.updated_date = DateTime.Now; ms_user.deleted_by = null; ms_user.deleted_date = null; db.Entry(ms_user).State = EntityState.Modified; } db.SaveChanges(); } ViewBag.ResultMessage = "Record inserted successfully."; } #endregion #region UPDATE_DATA else { ms_user ms_user = db.ms_user.Find(user_acc.user_id); ms_user.user_name = user_acc.user_name; if (!string.IsNullOrWhiteSpace(user_acc.user_password)) { ms_user.user_password = App_Helpers.CryptorHelper.Encrypt(user_acc.user_password, "MD5", true); } ms_user.user_type_id = user_acc.user_type_id; ms_user.fl_active = true; ms_user.updated_by = UserProfile.UserId; ms_user.updated_date = DateTime.Now; ms_user.deleted_by = null; ms_user.deleted_date = null; ms_employee emp = db.ms_employee.Find(user_acc.employee_id); if (emp != null) { ms_user.employee_id = emp.employee_id; 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; } db.Entry(ms_user).State = EntityState.Modified; ViewBag.ResultMessage = "Record updated successfully."; } #endregion transaction.Commit(); return(RedirectToAction("Index")); } catch (Exception ex) { transaction.Rollback(); ViewBag.ResultMessage = string.Format("Error occured, records rolledback. {0}", ex.Message); } } } return(View(user_acc)); }