コード例 #1
0
        public void ActionAdd(ModProduct_CustomersModel model)
        {
            if (model.RecordID > 0)
            {
                item = ModProduct_CustomersService.Instance.GetByID(model.RecordID);

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

                // khoi tao gia tri mac dinh khi insert
                item.Activity   = CPViewPage.UserPermissions.Approve;
                item.PointTotal = 1;
                item.CreateDate = DateTime.Now;
            }

            if (item.ID > 0)
            {
                model.NewPassword = "******";
            }

            ViewBag.Data  = item;
            ViewBag.Model = model;

            // Khởi tạo danh sách nhóm khách hàng
            item.CustomGroupInId  = ModProduct_CustomersGroupsService.Instance.GetListIdCustomersGroups_By_CustomerId(item.ID, true);
            item.CustomGroupOutId = ModProduct_CustomersGroupsService.Instance.GetListIdCustomersGroups_By_CustomerId(item.ID, false);

            ViewBag.GetListCustomersGroupsOut = GetListCustomersGroupsByCustomerId(item, false);
            ViewBag.GetListCustomersGroupsIn  = GetListCustomersGroupsByCustomerId(item, true);
        }
コード例 #2
0
 public void ActionSaveNew(ModProduct_CustomersModel model)
 {
     if (ValidSave(model))
     {
         SaveNewRedirect(model.RecordID, item.ID);
     }
 }
コード例 #3
0
 public void ActionSave(ModProduct_CustomersModel model)
 {
     if (ValidSave(model))
     {
         SaveRedirect();
     }
 }
コード例 #4
0
        public void ActionIndex(ModProduct_CustomersModel model)
        {
            // sap xep tu dong
            string orderBy = AutoSort(model.Sort);

            // tao danh sach
            var dbQuery = ModProduct_CustomersService.Instance.CreateQuery()
                          .Take(model.PageSize)
                          .OrderBy(orderBy)
                          .Skip(model.PageIndex * model.PageSize);

            ViewBag.Data      = dbQuery.ToList();
            model.TotalRecord = dbQuery.TotalRecord;
            ViewBag.Model     = model;
        }
コード例 #5
0
        private bool ValidSave(ModProduct_CustomersModel model)
        {
            TryUpdateModel(item);

            //chong hack
            item.ID = model.RecordID;

            ViewBag.Data  = item;
            ViewBag.Model = model;

            string sCustomGroupInId  = item.CustomGroupInId.Trim(',');
            string sCustomGroupOutId = item.CustomGroupOutId.Trim(',');

            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 (string.IsNullOrEmpty(item.UserName.Trim()))
            {
                CPViewPage.Message.ListMessage.Add("Yêu cầu nhập tên đăng nhập");
            }

            if (string.IsNullOrEmpty(model.NewPassword.Trim()))
            {
                if (item.ID <= 0)
                {
                    CPViewPage.Message.ListMessage.Add("Yêu cầu nhập mật khẩu");
                }
            }
            else
            {
                if (item.ID > 0)
                {
                    item.Pass = VSW.Lib.Global.Security.MD5(model.NewPassword);
                }
                else
                if (model.NewPassword.Trim().ToUpper() != "PASSWORD")
                {
                    item.Pass = VSW.Lib.Global.Security.MD5(model.NewPassword);
                }
            }

            if (string.IsNullOrEmpty(item.FullName.Trim()))
            {
                CPViewPage.Message.ListMessage.Add("Yêu cầu họ và tên khách hàng");
            }

            if (CPViewPage.Message.ListMessage.Count == 0)
            {
                try
                {
                    //save
                    ModProduct_CustomersService.Instance.Save(item);

                    // Cập nhật lại danh sách: Khách hàng - Nhóm khách hàng
                    Customer_Groups_Save(sCustomGroupInId, item);
                }
                catch (Exception ex)
                {
                    Global.Error.Write(ex);
                    CPViewPage.Message.ListMessage.Add(ex.Message);
                    return(false);
                }

                return(true);
            }

            return(false);
        }