예제 #1
0
        public void ActionAdd(ModDichVuCanhBaoIPModel model)
        {
            if (model.RecordID > 0)
            {
                entity = ModDichVuCanhBaoIPService.Instance.GetByID(model.RecordID);

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

                // khoi tao gia tri mac dinh khi insert
                entity.MenuID   = model.MenuID;
                entity.Activity = CPViewPage.UserPermissions.Approve;
                entity.Order    = GetMaxOrder(model);
            }

            ViewBag.Data  = entity;
            ViewBag.Model = model;
        }
예제 #2
0
        public void ActionAddDVCanhBao(ModDichVuCanhBaoEntity entity, MAppend append, string endCode)
        {
            string alert = string.Empty;

            ViewBag.DichVu = entity;
            ViewBag.Append = append;
            DateTime date   = DateTime.Now;
            int      userId = Lib.Global.CPLogin.UserID;

            try
            {
                // Lay ban ghi dang ky UCSC cua user
                var donDk = ModDonDangKyUCSCService.Instance.CreateQuery().Where(o => o.UserID == userId).ToSingle();
                if (donDk == null)
                {
                    ViewPage.Message.ListMessage.Add("Bạn chưa thực hiện đăng ký UCSC.");
                }

                string code = "DVCB" + ModDichVuCanhBaoService.Instance.GetMaxID();

                //entity.DonDangKyUCSCID = 0;
                entity.Name   = code;
                entity.Code   = Data.GetCode(code);
                entity.UserID = userId;
                entity.Order  = GetMaxOrder_DVCanhBao();

                try
                {
                    if (!string.IsNullOrEmpty(append.ThoiGian))
                    {
                        entity.Time = TimeSpan.Parse(append.ThoiGian);
                    }
                }
                catch (Exception e)
                {
                    ViewPage.Message.ListMessage.Add("Định dạng thời gian không đúng (HH:mm)");
                }

                // Lay ban ghi neu da ton tai
                ModDichVuCanhBaoEntity          curr   = null;
                List <ModDichVuCanhBaoIPEntity> ipCurr = null;
                if (!string.IsNullOrEmpty(endCode))
                {
                    curr = ModDichVuCanhBaoService.Instance.CreateQuery().Where(o => o.Name == endCode).ToSingle();
                    if (curr != null)
                    {
                        curr.MenuID = entity.MenuID;
                        curr.Time   = entity.Time;
                        ipCurr      = ModDichVuCanhBaoIPService.Instance.CreateQuery().Where(o => o.DichVuCanhBaoID == curr.ID).ToList();
                    }
                }

                entity.Published = date;
                entity.Activity  = true;
                int id = 0;

                // Danh sach IP
                var arr = append.M.Split(';');
                List <ModDichVuCanhBaoIPEntity> listIP = new List <ModDichVuCanhBaoIPEntity>();

                for (int j = 0; j < arr.Length; j++)
                {
                    if (string.IsNullOrEmpty(arr[j]))
                    {
                        continue;
                    }
                    var entityIP = new ModDichVuCanhBaoIPEntity
                    {
                        DichVuCanhBaoID = id,
                        MenuID          = entity.MenuID,
                        Name            = arr[j],
                        UserID          = userId,
                        Published       = DateTime.Now,
                        Published1      = null,
                        Order           = GetMaxOrder_DVCanhBaoIP(),
                        Activity        = true
                    };
                    listIP.Add(entityIP);
                }
                ViewBag.IPs = listIP;
                if (ViewPage.Message.ListMessage.Count == 0)
                {
                    if (curr != null)
                    {
                        ModDichVuCanhBaoService.Instance.Save(curr);
                        id = curr.ID;
                    }
                    else
                    {
                        entity.DonDangKyUCSCID = donDk.ID;
                        ViewBag.EndCode        = entity.Name;
                        id = ModDichVuCanhBaoService.Instance.Save(entity);
                    }

                    // Xoa IP cu
                    var ipDel = ModDichVuCanhBaoIPService.Instance.CreateQuery().Where(o => o.DichVuCanhBaoID == id).ToList();
                    if (ipDel != null)
                    {
                        ModDichVuCanhBaoIPService.Instance.Delete(ipDel);
                    }

                    listIP.ForEach(o => o.DichVuCanhBaoID = id);
                    ModDichVuCanhBaoIPService.Instance.Save(listIP);
                }
            }
            catch (Exception ex)
            {
                ViewPage.Message.ListMessage.Add("Lỗi đăng ký nhận cảnh báo! Hãy kiểm tra tính hợp lệ.");
            }

            if (ViewPage.Message.ListMessage.Count > 0)
            {
                ViewPage.Alert(string.Join("\n", ViewPage.Message.ListMessage));
            }
            else
            {
                ViewPage.Alert("Đăng ký nhận cảnh báo thành công.");
                //ViewPage.RefreshPage();
            }
        }