public void ActionAdd(ModProduct_PropertiesList_ValuesModel model) { if (model.RecordID > 0) { item = ModProduct_PropertiesList_ValuesService.Instance.GetByID(model.RecordID); // khoi tao gia tri mac dinh khi update } else { item = new ModProduct_PropertiesList_ValuesEntity(); // khoi tao gia tri mac dinh khi insert } ViewBag.Data = item; ViewBag.Model = model; }
private bool ValidSave(ModProduct_Info_DetailsModel model) { //TryUpdateModel(item); // Lấy thông tin Thuộc tính string sThuTu = model.DanhSachThuTuThuocTinh; if (string.IsNullOrEmpty(sThuTu)) return false; string[] ArrThuTuId = sThuTu.Split(','); ThuocTinh objThuocTinh = null; List<ThuocTinh> lstThuocTinh = new List<ThuocTinh>(); for (int i = 0; i < ArrThuTuId.Length; i++) { objThuocTinh = new ThuocTinh(); objThuocTinh.ProductInfoId = model.ProductInfoId; objThuocTinh.PropertiesGroupsId = model.PropertiesGroupsId; objThuocTinh.PropertiesListId = int.Parse(ArrThuTuId[i]); objThuocTinh.Content = CPViewPage.Request.Form["Value" + i]; if (CPViewPage.Request.Form["chkSaveData" + i] == null || CPViewPage.Request.Form["chkSaveData" + i] != "on") objThuocTinh.SaveData = false; else objThuocTinh.SaveData = true; // Thêm vào danh sách lstThuocTinh.Add(objThuocTinh); } ViewBag.Data = item; ViewBag.Model = model; try { // Xóa dữ liệu cũ ModProduct_Info_DetailsService.Instance.Delete("ProductInfoId=" + model.ProductInfoId); // Lấy danh sách insert List<ModProduct_Info_DetailsEntity> lstModProduct_Info_DetailsEntity = new List<ModProduct_Info_DetailsEntity>(); ModProduct_Info_DetailsEntity itemModProduct_Info_DetailsEntity = null; foreach (var itemThuocTinh in lstThuocTinh) { itemModProduct_Info_DetailsEntity = new ModProduct_Info_DetailsEntity(); itemModProduct_Info_DetailsEntity.ProductInfoId = itemThuocTinh.ProductInfoId; itemModProduct_Info_DetailsEntity.PropertiesGroupsId = itemThuocTinh.PropertiesGroupsId; itemModProduct_Info_DetailsEntity.PropertiesListId = itemThuocTinh.PropertiesListId; itemModProduct_Info_DetailsEntity.Content = itemThuocTinh.Content; // Thêm vào list lstModProduct_Info_DetailsEntity.Add(itemModProduct_Info_DetailsEntity); } // Insert vào DataBase ModProduct_Info_DetailsService.Instance.Save(lstModProduct_Info_DetailsEntity); // Thêm giá trị các thuộc tính vào bảng thuộc tính - giá trị List<ModProduct_PropertiesList_ValuesEntity> lstModProduct_PropertiesList_ValuesEntity = new List<ModProduct_PropertiesList_ValuesEntity>(); ModProduct_PropertiesList_ValuesEntity itemPropertiesList_ValuesEntity = null; List<ModProduct_PropertiesList_ValuesEntity> lstModProduct_PropertiesList_ValuesEntity_Check = ModProduct_PropertiesList_ValuesService.Instance.CreateQuery().WhereIn(o => o.PropertiesListId, sThuTu).ToList(); if (lstModProduct_PropertiesList_ValuesEntity_Check == null) lstModProduct_PropertiesList_ValuesEntity_Check = new List<ModProduct_PropertiesList_ValuesEntity>(); foreach (var itemThuocTinh in lstThuocTinh) { if (itemThuocTinh.SaveData == false) continue; // Kiểm tra xem giá trị tồn tại chưa itemPropertiesList_ValuesEntity = lstModProduct_PropertiesList_ValuesEntity_Check .Where(p => p.PropertiesListId == itemThuocTinh.PropertiesListId && p.Content.ToUpper() == itemThuocTinh.Content.ToUpper()).SingleOrDefault(); // Nếu tồn tại rồi thì không thêm nữa if (itemPropertiesList_ValuesEntity != null) continue; itemPropertiesList_ValuesEntity = new ModProduct_PropertiesList_ValuesEntity(); itemPropertiesList_ValuesEntity.PropertiesListId = itemThuocTinh.PropertiesListId; itemPropertiesList_ValuesEntity.Content = itemThuocTinh.Content; // Thêm vào danh sách lstModProduct_PropertiesList_ValuesEntity.Add(itemPropertiesList_ValuesEntity); } // Insert vào DataBase ModProduct_PropertiesList_ValuesService.Instance.Save(lstModProduct_PropertiesList_ValuesEntity); } catch (Exception ex) { Global.Error.Write(ex); CPViewPage.Message.ListMessage.Add(ex.Message); return false; } return true; }