public static SelectList GetSelectList_Module(object sValue) { var selectListItems = new List <SelectListItem>(); ModuleRepository ModuleRepository = new ModuleRepository(new Domain.ErpDbContext()); SelectListItem itemEmpty = new SelectListItem(); itemEmpty.Text = App_GlobalResources.Wording.Empty; itemEmpty.Value = null; selectListItems.Add(itemEmpty); try { var q = ModuleRepository.GetAllModule().OrderBy(item => item.Id); foreach (var i in q) { SelectListItem item = new SelectListItem(); item.Text = i.Name; item.Value = i.Name.ToString(); selectListItems.Add(item); } } catch { } var selectList = new SelectList(selectListItems, "Value", "Text", sValue); return(selectList); }
//public enum ActionName //{ // Create, // Edit, // Delete //} public static void Run(string moduleName, string actionName, int?IdData, int?UserId, object beforeEntityData = null, object afterEntityData = null, string DrugStore = null) { if (afterEntityData == null) { return; } string Entity = afterEntityData.GetType().Name; ProcessRepository processRepository = new ProcessRepository(new Domain.Crm.ErpCrmDbContext()); ProcessAppliedRepository processAppliedRepository = new ProcessAppliedRepository(new Domain.Crm.ErpCrmDbContext()); UserRepository userRepository = new UserRepository(new Domain.ErpDbContext()); //Lấy danh sách proccess theo thứ tự // var q = processRepository.GetAllProcess().Where(item => item.Category == "Workflow" && item.DataSource == Entity && item.IsActive.Value); List <Process> q = new List <Process>(); var action = processAppliedRepository.GetAllProcessApplied().Where(x => x.ModuleName == moduleName && x.ActionName == actionName).ToList(); foreach (var i in action) { var process = processRepository.GetProcessById(i.ProcessId.Value); q.Add(process); } //if (actionName == ActionName.Create) //{ // q = q.Where(item => item.RecordIsCreated.Value); //} //else if (actionName == ActionName.Edit) //{ //Check case user proceed assignee user //var assignedUserId_Before = beforeEntityData.GetType().GetProperties() // .Where(p => p.Name == "AssignedUserId").FirstOrDefault() // .GetGetMethod().Invoke(beforeEntityData, null); //var assignedUserId_After = afterEntityData.GetType().GetProperties() // .Where(p => p.Name == "AssignedUserId").FirstOrDefault() // .GetGetMethod().Invoke(afterEntityData, null); //var hasAssignee = assignedUserId_Before != assignedUserId_After ? true : false; // q = q.Where(item => (item.RecordIsAssigned.Value && hasAssignee) || item.RecordFieldsChanges.Value); //} //else if (actionName == ActionName.Delete) //{ // q = q.Where(item => item.RecordIsDeleted.Value); //} var qFiltered = q.ToList(); if (qFiltered != null && qFiltered.Count > 0) { ProcessActionRepository processActionRepository = new ProcessActionRepository(new Domain.Crm.ErpCrmDbContext()); ModuleRelationshipRepository moduleRelationshipRepository = new ModuleRelationshipRepository(new Domain.ErpDbContext()); ModuleRepository moduleRepository = new ModuleRepository(new Domain.ErpDbContext()); Dictionary <string, string> data = (from x in afterEntityData.GetType().GetProperties() select x) .ToDictionary(x => "{" + Entity + "." + x.Name + "}", x => (x.GetGetMethod().Invoke(afterEntityData, null) == null ? "" : x.GetGetMethod().Invoke(afterEntityData, null).ToString())); //Add module relationship data var moduleRelationship = moduleRelationshipRepository.GetAllModuleRelationship() .Where(item => item.First_ModuleName == Entity) .ToList(); if (moduleRelationship != null && moduleRelationship.Count > 0) { foreach (var item in moduleRelationship) { //Get table name var secondTableName = moduleRepository.GetAllModule().Where(i => i.Name == item.Second_ModuleName).FirstOrDefault().TableName; //Get data of each module_relationship item string keyValue = data["{" + Entity + "." + item.First_MetadataFieldName + "}"]; if (!string.IsNullOrEmpty(keyValue)) { string sql = string.Format("select * from [{0}] where [{1}] = {2}", secondTableName, item.Second_MetadataFieldName, keyValue); var q_temp = Domain.Helper.SqlHelper.QuerySQL(sql).FirstOrDefault(); if (q_temp != null) { foreach (KeyValuePair <string, object> c in q_temp) { data.Add("{" + item.Second_ModuleName_Alias + "." + c.Key + "}", c.Value == null ? "" : c.Value.ToString()); } } } } } foreach (var item in qFiltered) { //Lấy danh sách action theo thứ tự var actionList = processActionRepository.GetAllProcessAction().Where(x => x.ProcessId == item.Id).ToList(); if (UserId != null) { var user = userRepository.GetUserById(UserId.Value); item.QueryRecivedUser = item.QueryRecivedUser.Replace("{UserTypeId}", "'" + user.UserTypeId.ToString() + "'"); item.QueryRecivedUser = item.QueryRecivedUser.Replace("{BranchId}", "'" + user.BranchId.ToString() + "'"); item.QueryRecivedUser = item.QueryRecivedUser.Replace("{AssignedUserId}", "'" + user.Id.ToString() + "'"); } if (DrugStore != null) { item.QueryRecivedUser = item.QueryRecivedUser.Replace("{DrugStore}", DrugStore); } var collection = Domain.Helper.SqlHelper.QuerySQL <int>(item.QueryRecivedUser); foreach (var x in actionList) { switch (x.ActionType) { case "SendEmail": foreach (var ii in collection) { sendEmail(data, x.TemplateObject); } break; case "CreateTask": createTask(data, x.TemplateObject); break; case "CreateNotifications": foreach (var ii in collection) { createNotifications(data, x.TemplateObject, ii, moduleName, IdData); } break; default: break; } } } } }