public ReturnData AJAX_GetDetail(int idRole) { try { DataClassesDataContext db = new DataClassesDataContext(); Class_Role role = new Class_Role(); Class_Menu menu = new Class_Menu(); Class_Order_Status orderStatus = new Class_Order_Status(); Dictionary <string, dynamic> data = new Dictionary <string, dynamic>(); data.Add("Role", Dynamic_GetDetail(db, idRole)); data.Add("TreeMenus", role.GetTree_Menu(db, idRole)); data.Add("SelectedMenus", role.Dynamic_GetData_Menu_ByIDRole(idRole)); data.Add("TreeOrderStatus", GetTree_OrderStatus(db, idRole)); data.Add("SelectedOrderStatus", Dynamic_GetData_OrderStatus_ByIDRole(idRole)); data.Add("Notification", Dynamic_GetNotification_OrderStatus(db, idRole)); return(ReturnData.MessageSuccess("OK", data)); } catch (Exception ex) { Class_Log_Error log = new Class_Log_Error(); log.Insert(ex.Message, ex.StackTrace); return(ReturnData.MessageFailed(ex.Message, null)); } }
private IEnumerable <WITLibrary.JsTreeModel> GenerateUL_OrderStatus(DataClassesDataContext db, Class_Order_Status _orderStatus, IEnumerable <TBOrder_Status> orderStatuses, int idRole) { List <WITLibrary.JsTreeModel> _newOrderStatus = new List <WITLibrary.JsTreeModel>(); foreach (var orderStatus in orderStatuses) { if (orderStatus.TBRole_OrderStatus.AsEnumerable().Any()) { _newOrderStatus.Add(new WITLibrary.JsTreeModel { text = orderStatus.Name, state = new WITLibrary.JsTreeState { selected = orderStatus.TBRole_OrderStatus.AsEnumerable().FirstOrDefault(x => x.IDRole == idRole) != null }, li_attr = new WITLibrary.JsTreeAttr { id = orderStatus.IDOrderStatus.ToString() } }); } else { _newOrderStatus.Add(new WITLibrary.JsTreeModel { text = orderStatus.Name, li_attr = new WITLibrary.JsTreeAttr { id = orderStatus.IDOrderStatus.ToString() }, state = new WITLibrary.JsTreeState { selected = orderStatus.TBRole_OrderStatus.AsEnumerable().FirstOrDefault(x => x.IDRole == idRole) != null } }); } } return(_newOrderStatus.ToArray()); }
public IEnumerable <dynamic> GetTree_OrderStatus(DataClassesDataContext db, int idRole) { Class_Order_Status _orderStatus = new Class_Order_Status(); return(GenerateUL_OrderStatus(db, _orderStatus, _orderStatus.GetDataBy_IDOrderStatus(db), idRole)); }
public ReturnData AJAX_Update_OrderStatus(int idRole, int[] orderStatuses) { try { using (DataClassesDataContext db = new DataClassesDataContext()) { if (orderStatuses.Count() == 0) { return(ReturnData.MessageFailed("No selected menu to insert.", null)); } dynamic _role = Dynamic_GetDetail(db, idRole); if (_role == null) { return(ReturnData.MessageFailed("The requested resource does not exist.", null)); } TBRole_OrderStatus[] _oldOrdStatus = GetData_OrderStatus_ByIDRole(db, _role.IDRole); List <TBOrder_Status> _ordStatuses = new List <TBOrder_Status>(); Class_Order_Status _ordStatus = new Class_Order_Status(); foreach (int item in orderStatuses) { if (_oldOrdStatus.AsEnumerable().Where(x => x.IDOrderStatus == item).FirstOrDefault() == null) { TBOrder_Status _newData = _ordStatus.GetDetail(db, item); if (_ordStatus == null) { return(ReturnData.MessageFailed("Some order status does not exists.", null)); } _ordStatuses.Add(_newData); } } foreach (TBRole_OrderStatus item in _oldOrdStatus) { dynamic _item = orderStatuses.Where(x => x == item.IDOrderStatus).FirstOrDefault(); if (_item == 0) { db.TBRole_OrderStatus.DeleteOnSubmit(item); } //else //{ // if (!item.TBCategory.Active) // return ReturnData.MessageFailed(item.TBCategory.Name + " failed to insert, because " + item.TBCategory.Name + " does not active.", null); //} } db.SubmitChanges(); foreach (dynamic item in _ordStatuses) { TBRole_OrderStatus _newData = GetData_OrderStatus_ByIDRole(db, idRole).Where(x => x.IDOrderStatus == item.IDOrderStatus).FirstOrDefault(); if (_newData == null) { _newData = new TBRole_OrderStatus { IDRole = idRole, IDOrderStatus = item.IDOrderStatus, IsNotif = (GetData_OrderStatus_ByIDRole(db, idRole).Where(x => x.IsNotif == true).Count() == 0) ? true : false, DateInsert = DateTime.Now, DateLastUpdate = DateTime.Now, }; db.TBRole_OrderStatus.InsertOnSubmit(_newData); } } db.SubmitChanges(); Dictionary <string, dynamic> _result = new Dictionary <string, dynamic>(); Class_Order_Status orderStatus = new Class_Order_Status(); _result.Add("Role", Dynamic_GetDetail(db, idRole)); _result.Add("SelectedMenus", Dynamic_GetData_Menu_ByIDRole(idRole)); _result.Add("SelectedOrderStatus", Dynamic_GetData_OrderStatus_ByIDRole(idRole)); _result.Add("TreeMenus", GetTree_Menu(db, idRole)); _result.Add("TreeOrderStatus", GetTree_OrderStatus(db, idRole)); _result.Add("Notification", Dynamic_GetNotification_OrderStatus(db, idRole)); return(ReturnData.MessageSuccess(orderStatuses.Count() + " order status has been successfully updated.", _result)); } } catch (Exception ex) { Class_Log_Error log = new Class_Log_Error(); log.Insert(ex.Message, ex.StackTrace); return(ReturnData.MessageFailed(ex.Message, null)); } }