public void ActionSaveNew(ModProduct_Price_HistoryModel model)
 {
     if (ValidSave(model))
     {
         SaveNewRedirect(model.RecordID, item.ID);
     }
 }
 public void ActionSave(ModProduct_Price_HistoryModel model)
 {
     if (ValidSave(model))
     {
         SaveRedirect();
     }
 }
        public void ActionIndex(ModProduct_Price_HistoryModel model)
        {
            // sap xep tu dong
            string orderBy = AutoSort(model.Sort);

            if (model.ProductInfoId <= 0)
            {
                // tao danh sach
                var dbQuery = ModProduct_Price_HistoryService.Instance.CreateQuery()
                              .Take(model.PageSize)
                              .OrderBy(orderBy)
                              .Skip(model.PageIndex * model.PageSize);

                ViewBag.Data      = dbQuery.ToList();
                model.TotalRecord = dbQuery.TotalRecord;
            }
            else
            {
                var dbQuery = ModProduct_Price_HistoryService.Instance.CreateQuery()
                              .Where(o => o.ProductInfoId == model.ProductInfoId)
                              .Take(model.PageSize)
                              .OrderBy(orderBy)
                              .Skip(model.PageIndex * model.PageSize);

                ViewBag.Data      = dbQuery.ToList();
                model.TotalRecord = dbQuery.TotalRecord;
            }

            ViewBag.Model = model;
        }
        public void ActionAdd(ModProduct_Price_HistoryModel model)
        {
            if (model.RecordID > 0)
            {
                item = ModProduct_Price_HistoryService.Instance.GetByID(model.RecordID);

                // khoi tao gia tri mac dinh khi update
            }
            else
            {
                item = new ModProduct_Price_HistoryEntity();

                // khoi tao gia tri mac dinh khi insert
            }

            ViewBag.Data  = item;
            ViewBag.Model = model;
        }
        private bool ValidSave(ModProduct_Price_HistoryModel 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)
            {
                try
                {
                    //save
                    ModProduct_Price_HistoryService.Instance.Save(item);
                }
                catch (Exception ex)
                {
                    Global.Error.Write(ex);
                    CPViewPage.Message.ListMessage.Add(ex.Message);
                    return(false);
                }

                return(true);
            }

            return(false);
        }