public ActionResult Create(Check_Lists_Items model, string command) { try { ViewBag.Check_List_Item_Groups = dbcontext.Check_List_Item_Groups.ToList().Select(m => new { Code = "" + m.Group_Code + "-----[" + m.Description_Group + ']', ID = m.ID }).ToList(); if (ModelState.IsValid) { if (model.Check_List_Item_GroupsId == "0" || model.Check_List_Item_GroupsId == null) { ModelState.AddModelError("", HR.Resource.Personnel.CheckListItemGroupCodemustenter); return(View(model)); } Check_Lists_Items record = new Check_Lists_Items(); record.Check_Code = model.Check_Code; record.Description = model.Description; record.Description_Alternative = model.Description_Alternative; record.Is_Mandatory = model.Is_Mandatory; record.Check_List_Item_GroupsId = model.Check_List_Item_GroupsId; var Question_GroupId = int.Parse(model.Check_List_Item_GroupsId); var group = dbcontext.Check_List_Item_Groups.FirstOrDefault(m => m.ID == Question_GroupId); record.Check_List_Item_Groups = group; var item = dbcontext.Check_Lists_Items.Add(record); dbcontext.SaveChanges(); ///// //group.check_items.Add(item); //dbcontext.SaveChanges(); /////add new item to eos var ESO = dbcontext.EOS_Request.Where(m => m.Check_List_Item_Groups.ID == Question_GroupId); foreach (var item1 in ESO) { var interview = new check_list_EOS(); interview.item = item; interview.interpolation = false; interview.EOS = item1; var inter = dbcontext.check_list_EOS.Add(interview); } dbcontext.SaveChanges(); return(RedirectToAction("Index")); } else { return(View(model)); } } catch (DbUpdateException) { TempData["Message"] = HR.Resource.Basic.thiscodeIsalreadyexists; return(View(model)); } catch (Exception e) { return(View(model)); } }
public ActionResult create(EOS_VM model, string command) { ViewBag.employee = dbcontext.Employee_Profile.ToList().Select(m => new { Code = "" + m.Code + "-----[" + m.Full_Name + ']', ID = m.ID }).ToList(); ViewBag.interview = dbcontext.EOS_Interview_Questions_Groups.ToList().Select(m => new { Code = "" + m.Questions_Group_Code + "-----[" + m.Description_of + ']', ID = m.ID }).ToList(); ViewBag.checklist = dbcontext.Check_List_Item_Groups.ToList().Select(m => new { Code = "" + m.Group_Code + "-----[" + m.Description_Group + ']', ID = m.ID }).ToList(); try { if (model.selected_employee == 0) { TempData["Message"] = HR.Resource.pers_2.youmustchooseemployee; return(View(model)); } var record = new EOS_Request(); record = model.EOS; if (model.selected_employee > 0) { var emp = dbcontext.Employee_Profile.FirstOrDefault(m => m.ID == model.selected_employee); record.Employee = emp; record.statID = emp.ID; } ///////////////status//////////////////////// record.check_status = check_status.created; record.sss = record.check_status.GetTypeCode().ToString(); var Date = Convert.ToDateTime("1/1/1900"); var s = new status { statu = check_status.created, Type = Models.Infra.Type.employee_record, approved_bydate = Date, cancaled_bydate = Date, created_bydate = DateTime.Now.Date, Rejected_bydate = Date, return_to_reviewdate = Date }; s.created_by = User.Identity.GetUserName(); var st = dbcontext.status.Add(s); dbcontext.SaveChanges(); record.status = st; /////////////////checklist//////////////////// List <check_list_EOS> check_list = new List <check_list_EOS>(); if (model.selected_EOS_group_checklist > 0) { ///// var group = dbcontext.Check_List_Item_Groups.FirstOrDefault(m => m.ID == model.selected_EOS_group_checklist); record.Check_List_Item_Groups = group; ///// var items = group.check_items; foreach (var item in items) { var item_of_chick = new check_list_EOS(); item_of_chick.item = item; item_of_chick.interpolation = false; var inter = dbcontext.check_list_EOS.Add(item_of_chick); dbcontext.SaveChanges(); check_list.Add(inter); } } else { record.Check_List_Item_Groups = null; } record.Check_List = check_list; ////////////////interview///////////////////// List <Answer_EOS> Answer_EOS_list = new List <Answer_EOS>(); if (model.selected_EOS_group_interview > 0) { ///// var group = dbcontext.EOS_Interview_Questions_Groups.FirstOrDefault(m => m.ID == model.selected_EOS_group_interview); record.EOS_group = group; ///// var questions = group.questions; foreach (var item in questions) { var interview = new Answer_EOS(); interview.question = item; interview.answer = ""; interview.Notes = ""; var inter = dbcontext.Answer_EOS.Add(interview); dbcontext.SaveChanges(); Answer_EOS_list.Add(inter); } } else { record.EOS_group = null; } record.Answer_EOS_interview = Answer_EOS_list; ////////////////create////////////////////// record.req_date = record.Requset_date.ToShortDateString(); record.eos_Date = record.date_of_eos_interview.ToShortDateString(); record.name_state = nameof(check_status.created); var t = (EOS_type)(int)record.EOS_type; if (t == 0) { record.name_type = nameof(EOS_type.Early_EOS); } else { record.name_type = t.ToString(); } record.note = model.EOS.note; dbcontext.EOS_Request.Add(record); dbcontext.SaveChanges(); //=================================check for alert================================== var get_result_check = HR.Controllers.check.check_alert("EOS 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(); } //================================================================================== ///////////////click EOS interview///////// if (command == "Submit2") { return(RedirectToAction("interview", new { id = record.ID })); } else if (command == "Submit3") { return(RedirectToAction("chick", new { id = record.ID })); } //var currentTime = DateTime.Now; //HR.Models.NOtification.NotificationComponent NC = new HR.Models.NOtification.NotificationComponent(); //NC.RegisterNotification(currentTime); ////////////back to index ///////////////// return(RedirectToAction("index")); } catch (DbUpdateException e) { TempData["Message"] = HR.Resource.organ.thiscodeIsalreadyexists; return(View(model)); } catch (Exception e) { return(View(model)); } }
public ActionResult edit(EOS_VM model, string command) { try { ViewBag.employee = dbcontext.Employee_Profile.ToList().Select(m => new { Code = "" + m.Code + "-----[" + m.Full_Name + ']', ID = m.ID }).ToList(); ViewBag.interview = dbcontext.EOS_Interview_Questions_Groups.ToList().Select(m => new { Code = "" + m.Questions_Group_Code + "-----[" + m.Description_of + ']', ID = m.ID }).ToList(); ViewBag.checklist = dbcontext.Check_List_Item_Groups.ToList().Select(m => new { Code = "" + m.Group_Code + "-----[" + m.Description_Group + ']', ID = m.ID }).ToList(); if (model.selected_employee == 0) { TempData["Message"] = HR.Resource.pers_2.youmustchooseemployee; return(View(model)); } /////////////////////edit////////////////////////// var record = dbcontext.EOS_Request.FirstOrDefault(m => m.ID == model.EOS.ID); if (model.selected_employee > 0) { var emp = dbcontext.Employee_Profile.FirstOrDefault(m => m.ID == model.selected_employee); record.Employee = emp; record.statID = emp.ID; } else { record.Employee = null; } record.are_the_employee_has_a_loan_or_advanced = model.EOS.are_the_employee_has_a_loan_or_advanced; record.are_the_settlement_transferred_to_payroll = model.EOS.are_the_settlement_transferred_to_payroll; record.Date_of_EOS = model.EOS.Date_of_EOS; record.date_of_eos_interview = model.EOS.date_of_eos_interview; record.date_of_settlement = model.EOS.date_of_settlement; record.EOS_type = model.EOS.EOS_type; record.last_Date_of_work_after_notice_period = model.EOS.last_Date_of_work_after_notice_period; record.last_work_day_before_request = model.EOS.last_work_day_before_request; record.note = model.EOS.note; record.Notice_period = model.EOS.Notice_period; record.Notice_period_type = model.EOS.Notice_period_type; record.Requset_date = model.EOS.Requset_date; record.note = model.EOS.note; //////////////////////checklist///////////////////////// if (model.selected_EOS_group_checklist == 0) { var old_answer = record.Check_List; record.Check_List = new List <check_list_EOS>(); dbcontext.check_list_EOS.RemoveRange(old_answer); record.Check_List_Item_Groups = null; dbcontext.SaveChanges(); } else if (model.selected_EOS_group_checklist > 0) { if (record.Check_List_Item_Groups == null || (model.selected_EOS_group_checklist != record.Check_List_Item_Groups.ID)) { List <check_list_EOS> answer_list = new List <check_list_EOS>(); var old_answer = record.Check_List; record.Check_List = new List <check_list_EOS>(); dbcontext.check_list_EOS.RemoveRange(old_answer); dbcontext.SaveChanges(); record.Check_List_Item_Groups = dbcontext.Check_List_Item_Groups.FirstOrDefault(m => m.ID == model.selected_EOS_group_checklist); var questions = dbcontext.Check_Lists_Items.Where(m => m.Check_List_Item_Groups.ID == record.Check_List_Item_Groups.ID); foreach (var item in questions) { var answer = new check_list_EOS(); answer.item = item; answer.interpolation = false; var inter = dbcontext.check_list_EOS.Add(answer); answer_list.Add(inter); } dbcontext.SaveChanges(); record.Check_List = answer_list; } } dbcontext.SaveChanges(); //////////////////////interview////////////////////////// if (model.selected_EOS_group_interview == 0) { var old_answer = record.Answer_EOS_interview; record.Answer_EOS_interview = new List <Answer_EOS>(); dbcontext.Answer_EOS.RemoveRange(old_answer); record.EOS_group = null; dbcontext.SaveChanges(); } else if (model.selected_EOS_group_interview > 0) { if (record.EOS_group == null || (model.selected_EOS_group_interview != record.EOS_group.ID)) { List <Answer_EOS> answer_list = new List <Answer_EOS>(); var old_answer = record.Answer_EOS_interview; record.Answer_EOS_interview = new List <Answer_EOS>(); dbcontext.Answer_EOS.RemoveRange(old_answer); dbcontext.SaveChanges(); record.EOS_group = dbcontext.EOS_Interview_Questions_Groups.FirstOrDefault(m => m.ID == model.selected_EOS_group_interview); var questions = dbcontext.Definition_of_EOS_Interview_Questions.Where(m => m.EOS_Interview_Questions_Groups.ID == record.EOS_group.ID); foreach (var item in questions) { var answer = new Answer_EOS(); answer.question = item; answer.Notes = ""; answer.answer = ""; var inter = dbcontext.Answer_EOS.Add(answer); answer_list.Add(inter); } dbcontext.SaveChanges(); record.Answer_EOS_interview = answer_list; } } record.sss = record.check_status.GetTypeCode().ToString(); record.req_date = record.Requset_date.ToShortDateString(); record.eos_Date = record.date_of_eos_interview.ToShortDateString(); var t = (EOS_type)(int)record.EOS_type; record.name_type = t.ToString(); dbcontext.SaveChanges(); //=================================check for alert================================== var get_result_check = HR.Controllers.check.check_alert("EOS transaction", HR.Models.user.Action.edit, 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(); } //================================================================================== if (command == "Submit2") { return(RedirectToAction("interview", new { id = record.ID })); } else if (command == "Submit3") { return(RedirectToAction("chick", new { id = record.ID })); } return(RedirectToAction("index")); } catch (DbUpdateException) { TempData["Message"] = HR.Resource.organ.thiscodeIsalreadyexists; return(View(model)); } catch (Exception e) { return(View(model)); } }