public void ActionSaveNew(ModProduct_GroupsModel model) { if (ValidSave(model)) { SaveNewRedirect(model.RecordID, item.ID); } }
public void ActionApply(ModProduct_GroupsModel model) { if (ValidSave(model)) { ApplyRedirect(model.RecordID, item.ID); } }
public void ActionSave(ModProduct_GroupsModel model) { if (ValidSave(model)) { SaveRedirect(); } }
public void ActionAdd(ModProduct_GroupsModel model) { if (model.RecordID > 0) { item = ModProduct_GroupsService.Instance.GetByID(model.RecordID); // khoi tao gia tri mac dinh khi update } else { item = new ModProduct_GroupsEntity(); // khoi tao gia tri mac dinh khi insert item.Activity = CPViewPage.UserPermissions.Approve; item.CreateDate = DateTime.Now; item.ParentId = 0; } string sPropertiesGroupsInId = string.Empty; string sPropertiesGroupsOutId = string.Empty; ViewBag.GetListPropertiesGroupsIn = GetListPropertiesGroupByProductId(item, true, ref sPropertiesGroupsInId); ViewBag.GetListPropertiesGroupsOut = GetListPropertiesGroupByProductId(item, false, ref sPropertiesGroupsOutId); // Khởi tạo danh sách thuộc tính model.PropertiesGroupsInId = sPropertiesGroupsInId; model.PropertiesGroupsOutId = sPropertiesGroupsOutId; ViewBag.Data = item; ViewBag.Model = model; }
public void ActionIndex(ModProduct_GroupsModel model) { // sap xep tu dong string orderBy = AutoSort(model.Sort); // tao danh sach var dbQuery = ModProduct_GroupsService.Instance.CreateQuery() .Where(!string.IsNullOrEmpty(model.SearchText), o => o.Name.Contains(model.SearchText)) .Where(o => o.ShowHide == true) // Chỉ load những nhóm được phép hiển thị .Take(model.PageSize) .OrderBy(orderBy) .Skip(model.PageIndex * model.PageSize); ViewBag.Data = dbQuery.ToList(); model.TotalRecord = dbQuery.TotalRecord; ViewBag.Model = model; }
private bool ValidSave(ModProduct_GroupsModel model) { TryUpdateModel(item); //chong hack item.ID = model.RecordID; ViewBag.Data = item; ViewBag.Model = model; CPViewPage.Message.MessageType = Message.MessageTypeEnum.Error; //kiem tra quyen han if ((model.RecordID < 1 && !CPViewPage.UserPermissions.Add) || (model.RecordID > 0 && !CPViewPage.UserPermissions.Edit)) { CPViewPage.Message.ListMessage.Add("Quyền hạn chế."); } if (CPViewPage.Message.ListMessage.Count == 0) { // Kiểm tra mã xem có trùng với mã nào khác đã có không string sMessError = string.Empty; if (ModProduct_GroupsService.Instance.DuplicateCode(item.Code, model.RecordID, ref sMessError)) { if (string.IsNullOrEmpty(sMessError)) { CPViewPage.Message.ListMessage.Add(CPViewControl.ShowMessDuplicate("Mã nhóm sản phẩm", item.Code)); } else { CPViewPage.Message.ListMessage.Add("Lỗi phát sinh: " + sMessError); } return(false); } //neu khong nhap code -> tu sinh if (item.Code.Trim() == string.Empty) { item.Code = Data.GetCode(item.Name); } #region Tạo mới chuyên mục // Tạo mới Chuyên mục WebMenuEntity objWebMenuEntity = null; // Lấy thông tin của chủng loại Cha var dbQuery = ModProduct_GroupsService.Instance.CreateQuery() .Where(o => o.ID == item.ParentId).ToList(); if (dbQuery != null && dbQuery.Count > 0) { // Parent ID mới của chuyên mục item.Web_MenuParentId = dbQuery[0].Web_MenuId; // Nếu tạo mới if (item.ID <= 0) { objWebMenuEntity = new WebMenuEntity(); // Thêm mới nhận vào là MEnu cha objWebMenuEntity.ParentID = dbQuery[0].Web_MenuId; } else { var dbQueryWebMenu = WebMenuService.Instance.CreateQuery() .Where(o => o.ID == item.Web_MenuId).ToList(); if (dbQueryWebMenu != null && dbQueryWebMenu.Count > 0) { objWebMenuEntity = dbQueryWebMenu[0]; } else { objWebMenuEntity = new WebMenuEntity(); } // Cập nhật lại ID cha objWebMenuEntity.ParentID = item.Web_MenuParentId; } objWebMenuEntity.Name = item.Name; objWebMenuEntity.Code = Data.GetCode(item.Name); objWebMenuEntity.Type = "Product_Info"; objWebMenuEntity.Activity = true; objWebMenuEntity.LangID = model.LangID; objWebMenuEntity.Order = Convert.ToInt32(DateTime.Now.ToString("yyyyMMmmss")); try { // Tạo mới chuyên mục thành công WebMenuService.Instance.Save(objWebMenuEntity); } catch (Exception ex) { // Tạo mới chuyên mục thất bại CPViewPage.Message.ListMessage.Add(ex.Message); } } #endregion // Lấy thông tin chuyên mục cho chủng loại item.Web_MenuId = objWebMenuEntity.ID; item.ShowHide = true; try { //save ModProduct_GroupsService.Instance.Save(item); string sArrPropertiesGroupsIn = model.PropertiesGroupsInId.Trim(); // update UpdateProductGroups_PropertiesGroups(item.ID, sArrPropertiesGroupsIn); } catch (Exception ex) { Global.Error.Write(ex); CPViewPage.Message.ListMessage.Add(ex.Message); return(false); } return(true); } return(false); }