public ActionResult Create() { ViewBag.employee = dbcontext.Employee_Profile.ToList().Select(m => new { Code = "" + m.Code + "-----[" + m.Full_Name + ']', ID = m.ID }).ToList(); ViewBag.group = dbcontext.Employee_Recodes_Group.ToList().Select(m => new { Code = "" + m.Record_Group_Code + "-----[" + m.Record_Group_Description + ']', ID = m.ID }).ToList(); var record = new Employee_records { record_amount = 0.0, record_value = 0.0, Record_date = DateTime.Now.Date, Record_expire_date = DateTime.Now.Date, Effictive_date = DateTime.Now.Date }; var my_model = new employee_recordVM { record = record, selectedgroup = 0, selectedEmpoyee = 0 }; try { var stru = dbcontext.StructureModels.FirstOrDefault(m => m.All_Models == ChModels.Personnel).Structure_Code; var model = dbcontext.Employee_records.ToList(); if (model.Count() == 0) { record.Code = stru + "1"; } else { record.Code = stru + (model.LastOrDefault().ID + 1).ToString(); } my_model.record = record; return(View(my_model)); } catch (Exception e) { return(View(my_model)); } }
public ActionResult Create(employee_recordVM model) { var username = User.Identity.GetUserName(); ViewBag.employee = dbcontext.Employee_Profile.ToList().Select(m => new { Code = "" + m.Code + "-----[" + m.Full_Name + ']', ID = m.ID }).ToList(); ViewBag.group = dbcontext.Employee_Recodes_Group.ToList().Select(m => new { Code = "" + m.Record_Group_Code + "-----[" + m.Record_Group_Description + ']', ID = m.ID }).ToList(); try { var record = new Employee_records(); record = model.record; if (model.selectedEmpoyee == 0) { TempData["Message"] = HR.Resource.pers_2.youmustchooseemployee; return(View(model)); } if (model.selectedEmpoyee > 0) { var emp = dbcontext.Employee_Profile.FirstOrDefault(m => m.ID == model.selectedEmpoyee); record.Employee_Profile = emp; record.statID = emp.ID; } if (model.selectedgroup > 0) { record.Employee_Recodes_Group = dbcontext.Employee_Recodes_Group.FirstOrDefault(m => m.ID == model.selectedgroup); } record.check_status = check_status.created; var Date = Convert.ToDateTime("1/1/1900"); var s = new status { statu = check_status.created, created_by = username, Type = Models.Infra.Type.employee_record, approved_bydate = Date, cancaled_bydate = Date, created_bydate = DateTime.Now.Date, Rejected_bydate = Date, return_to_reviewdate = Date }; var st = dbcontext.status.Add(s); dbcontext.SaveChanges(); record.status = st; record.sss = record.Record_date.ToShortDateString(); record.name_state = nameof(check_status.created); dbcontext.Employee_records.Add(record); dbcontext.SaveChanges(); //=================================check for alert================================== var get_result_check = HR.Controllers.check.check_alert("employee record transaction", HR.Models.user.Action.Create, type_field.form); if (get_result_check != null) { var inbox = new Models.user.Alert_inbox { send_from_user_id = User.Identity.GetUserId(), send_to_user_id = get_result_check.send_to_ID_user, title = get_result_check.Subject, Subject = get_result_check.Message }; if (get_result_check.until != null) { if (get_result_check.until.Value.Year != 0001) { inbox.until = get_result_check.until; } } dbcontext.Alert_inbox.Add(inbox); dbcontext.SaveChanges(); } //================================================================================== return(RedirectToAction("index")); } catch (DbUpdateException e) { TempData["Message"] = HR.Resource.organ.thiscodeIsalreadyexists; return(View(model)); } catch (Exception e) { return(View(model)); } }