Пример #1
0
 public void ActionSaveNew(SysResourceModel model)
 {
     if (ValidSave(model))
     {
         SaveNewRedirect(model.RecordID, item.ID);
     }
 }
Пример #2
0
 public void ActionSave(SysResourceModel model)
 {
     if (ValidSave(model))
     {
         SaveRedirect();
     }
 }
Пример #3
0
        public void ActionIndex(SysResourceModel model)
        {
            // sap xep tu dong
            string orderBy = AutoSort(model.Sort, "[Code]");

            // tao danh sach
            var dbQuery = WebResourceService.Instance.CreateQuery()
                          .Where(o => o.LangID == model.LangID)
                          .Where(!string.IsNullOrEmpty(model.SearchText), o => o.Code.Contains(model.SearchText))
                          .Take(model.PageSize)
                          .OrderBy(orderBy)
                          .Skip(model.PageIndex * model.PageSize);

            ViewBag.Data      = dbQuery.ToList();
            model.TotalRecord = dbQuery.TotalRecord;
            ViewBag.Model     = model;
        }
Пример #4
0
        public void ActionAdd(SysResourceModel model)
        {
            if (model.RecordID > 0)
            {
                item = WebResourceService.Instance.GetByID(model.RecordID);

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

                // khoi tao gia tri mac dinh khi insert
                item.LangID = model.LangID;
            }

            ViewBag.Data  = item;
            ViewBag.Model = model;
        }
Пример #5
0
        private bool ValidSave(SysResourceModel model)
        {
            TryUpdateModel(item);

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

            CPViewPage.Message.MessageType = Message.MessageTypeEnum.Error;

            //kiem tra ma
            if (item.Code.Trim() == string.Empty)
            {
                CPViewPage.Message.ListMessage.Add("Nhập mã.");
            }

            //kiem tra ton tai
            if (model.RecordID < 1 && WebResourceService.Instance.CP_HasExists(item.Code, item.LangID))
            {
                CPViewPage.Message.ListMessage.Add("Mã đã tồn tại.");
            }

            if (CPViewPage.Message.ListMessage.Count == 0)
            {
                try
                {
                    //save
                    WebResourceService.Instance.Save(item);
                }
                catch (Exception ex)
                {
                    Global.Error.Write(ex);
                    CPViewPage.Message.ListMessage.Add(ex.Message);
                    return(false);
                }

                return(true);
            }

            return(false);
        }
Пример #6
0
        public void ActionApply(SysResourceModel model)
        {
            if (model.Type > 0)
            {
                if (model.Type == 1 && !string.IsNullOrEmpty(model.Value1))
                {
                    string[] Arr = model.Value1.Split('\n');
                    for (int i = 0; i < Arr.Length; i++)
                    {
                        string s = Arr[i].Trim();

                        if (string.IsNullOrEmpty(s))
                        {
                            continue;
                        }

                        if (s.StartsWith("//"))
                        {
                            continue;
                        }

                        int index = s.IndexOf('=');
                        if (index == -1)
                        {
                            continue;
                        }

                        string key   = s.Substring(0, index).Trim();
                        string value = s.Substring(index + 1).Trim();

                        if (WebResourceService.Instance.CP_HasExists(key, model.LangID1))
                        {
                            if (model.Overwrite1)
                            {
                                var rs = WebResourceService.Instance.CreateQuery()
                                         .Where(o => o.LangID == model.LangID1 && o.Code == key)
                                         .ToSingle();

                                rs.Value = value;

                                WebResourceService.Instance.Save(rs, o => o.Value);
                            }
                        }
                        else
                        {
                            WebResourceService.Instance.Save(new WebResourceEntity
                            {
                                LangID = model.LangID1,
                                Code   = key,
                                Value  = value
                            });
                        }
                    }
                }
                else if (model.Type == 2)
                {
                    if (model.FLangID2 != model.TLangID2)
                    {
                        var listRS = WebResourceService.Instance.CreateQuery()
                                     .Where(o => o.LangID == model.FLangID2)
                                     .ToList();

                        for (int i = 0; listRS != null && i < listRS.Count; i++)
                        {
                            string key   = listRS[i].Code;
                            string value = listRS[i].Value;

                            if (WebResourceService.Instance.CP_HasExists(key, model.TLangID2))
                            {
                                if (model.Overwrite2)
                                {
                                    var rs = WebResourceService.Instance.CreateQuery()
                                             .Where(o => o.LangID == model.TLangID2 && o.Code == key)
                                             .ToSingle();

                                    rs.Value = value;

                                    WebResourceService.Instance.Save(rs, o => o.Value);
                                }
                            }
                            else
                            {
                                WebResourceService.Instance.Save(new WebResourceEntity
                                {
                                    LangID = model.TLangID2,
                                    Code   = key,
                                    Value  = value
                                });
                            }
                        }
                    }
                }
                else if (model.Type == 3)
                {
                    //var listRS = WebResourceService.Instance.CreateQuery()
                    //                .Where(o => o.LangID == model.LangID3)
                    //                .ToList();

                    //for (int i = 0; listRS != null && i < listRS.Count; i++)
                    //{
                    //    string key = listRS[i].Code;
                    //    string value = GetTranslate(listRS[i].Value, model.FLangID3, model.TLangID3);

                    //    if (value != string.Empty)
                    //    {
                    //        listRS[i].Value = value;

                    //        WebResourceService.Instance.Save(listRS[i], o => o.Value);
                    //    }
                    //}
                }

                if ((model.Type == 1 && !string.IsNullOrEmpty(model.Value1)) || model.Type == 2 || model.Type == 3)
                {
                    CPViewPage.SetMessage("Thông tin đã cập nhật.");

                    return;
                }
            }

            if (ValidSave(model))
            {
                ApplyRedirect(model.RecordID, item.ID);
            }
        }
Пример #7
0
 public void ActionImport(SysResourceModel model)
 {
     ViewBag.Model = model;
 }
Пример #8
0
 public void ActionUpload(SysResourceModel model)
 {
     CPViewPage.Script("Redirect", "VSWRedirect('Import')");
 }