Esempio n. 1
0
        public ActionResult SaveItem(Banners model)
        {
            string       ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            int          IdDC           = Int32.Parse(MyModels.Decode(model.Ids, API.Models.Settings.SecretId + ControllerName).ToString());
            BannersModel data           = new BannersModel()
            {
                Item = model
            };

            if (ModelState.IsValid)
            {
                if (model.Id == IdDC)
                {
                    model.CreatedBy  = int.Parse(HttpContext.Request.Headers["Id"]);
                    model.ModifiedBy = int.Parse(HttpContext.Request.Headers["Id"]);
                    BannersService.SaveItem(model);
                    if (model.Id > 0)
                    {
                        TempData["MessageSuccess"] = "Cập nhật thành công";
                    }
                    else
                    {
                        TempData["MessageSuccess"] = "Thêm mới thành công";
                    }
                    return(RedirectToAction("Index", new { CatId = model.CatId, IdCoQuan = model.IdCoQuan }));
                }
            }
            else
            {
                data.ListItemsCategories = BannersCategoriesService.GetListSelectItems();
                data.ListDMCoQuan        = DMCoQuanService.GetListByLoaiCoQuan(0, 1);
            }
            return(View(data));
        }
Esempio n. 2
0
        public IActionResult SaveItem(string Id = null, int CatId = 0, int IdCoQuan = 1)
        {
            BannersModel data           = new BannersModel();
            string       ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            int          IdDC           = Int32.Parse(MyModels.Decode(Id, API.Models.Settings.SecretId + ControllerName).ToString());

            data.SearchData = new SearchBanners()
            {
                CurrentPage = 0, ItemsPerPage = 10, Keyword = "", CatId = CatId, IdCoQuan = IdCoQuan
            };
            data.ListItemsCategories = BannersCategoriesService.GetListSelectItems();
            data.ListDMCoQuan        = DMCoQuanService.GetListByLoaiCoQuan(0, 1);
            if (IdDC == 0)
            {
                data.Item = new Banners()
                {
                    CatId = CatId, Status = true
                };
            }
            else
            {
                data.Item = BannersService.GetItem(IdDC, API.Models.Settings.SecretId + ControllerName);
            }


            return(View(data));
        }
Esempio n. 3
0
        public IActionResult Index([FromQuery] SearchBanners dto)
        {
            int TotalItems = 0;

            if (dto.IdCoQuan == 0)
            {
                dto.IdCoQuan = 1;
            }
            string       ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            BannersModel data           = new BannersModel()
            {
                SearchData = dto
            };

            data.ListItems = BannersService.GetListPagination(data.SearchData, API.Models.Settings.SecretId + ControllerName);
            if (data.ListItems != null && data.ListItems.Count() > 0)
            {
                TotalItems = data.ListItems[0].TotalRows;
            }
            data.ListDMCoQuan = DMCoQuanService.GetListByLoaiCoQuan(0, 1);
            data.Pagination   = new Models.Partial.PartialPagination()
            {
                CurrentPage = data.SearchData.CurrentPage, ItemsPerPage = data.SearchData.ItemsPerPage, TotalItems = TotalItems, QueryString = Request.QueryString.ToString()
            };
            data.ListItemsCategories = BannersCategoriesService.GetListSelectItems();
            return(View(data));
        }
        public HttpResponseMessage GetBannerPictures()
        {
            DataChangingLogBuss buss = new DataChangingLogBuss();
            var model = new BannersModel();

            model.LastModifyTime = buss.GetDateChangingTimeByType("Banner");
            model.ImgPaths       = buss.GetBannerPaths();

            return(ToJson(model));
        }
Esempio n. 5
0
        /// <summary>
        /// Обновляем запись баннера
        /// </summary>
        /// <param name="id">Идентификатор</param>
        /// <param name="item">Модель баннера</param>
        /// <param name="userId">Id-пользователя</param>
        /// <param name="IP">ip-адрес</param>
        /// <returns></returns>
        public override bool updateBanner(Guid id, BannersModel item)
        {
            using (var db = new CMSdb(_context))
            {
                var query = db.content_bannerss.Where(w => w.id.Equals(id));

                if (query.Any())
                {
                    string img = (item.Photo != null) ? item.Photo.Url: null;

                    query
                    .Set(s => s.c_title, item.Title)
                    .Set(s => s.c_photo, item.Photo.Url)
                    .Set(s => s.c_url, item.Url)
                    .Set(s => s.c_text, item.Text)
                    .Set(s => s.d_date, item.Date)
                    .Set(s => s.b_disabled, item.Disabled)
                    .Set(s => s.f_section, item.Section)
                    .Set(s => s.b_locked, item.Locked)
                    .Update();

                    // логирование
                    //insertLog(userId, IP, "update", id, string.Empty, "Banners", item.Title);
                    var log = new LogModel()
                    {
                        Site     = _domain,
                        Section  = LogSection.Banners,
                        Action   = LogAction.update,
                        PageId   = id,
                        PageName = item.Title,
                        UserId   = _currentUserId,
                        IP       = _ip,
                    };
                    insertLog(log);

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Esempio n. 6
0
        public ActionResult Update(BannersModel model)
        {
            if (!ModelState.IsValid)
            {
                return(new AjaxResult().Alert(T(Constants.Messages.InvalidModel)));
            }

            BannerInfo item = model.Id == 0 ? new BannerInfo() : service.GetById(model.Id);

            item.LanguageCode = "vi-VN";
            item.CategoryId   = model.CategoryId;
            item.Type         = 0;
            item.Title        = model.Title;
            item.Caption      = model.Caption;
            item.Url          = model.Url;
            item.ImageUrl     = model.ImageUrl;
            item.SortOrder    = model.SortOrder;
            service.Save(item);

            return(new AjaxResult().NotifyMessage("UPDATE_ENTITY_COMPLETE").Alert(T("Đã cập nhật thành công.")));
        }
Esempio n. 7
0
        public ActionResult Edit(int id)
        {
            WorkContext.Breadcrumbs.Add(new Breadcrumb {
                Text = T("Quản lý banner"), Url = "#"
            });
            WorkContext.Breadcrumbs.Add(new Breadcrumb {
                Text = T("Thông tin banner"), Url = Url.Action("Index")
            });
            var model = new BannersModel();

            if (id > 0)
            {
                model = this.service.GetById(id);
            }

            var result = new ControlFormResult <BannersModel>(model);

            result.Title                = this.T("Thông tin banner");
            result.FormMethod           = FormMethod.Post;
            result.UpdateActionName     = "Update";
            result.ShowCancelButton     = false;
            result.ShowBoxHeader        = false;
            result.FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml;
            result.FormWrapperEndHtml   = Constants.Form.FormWrapperEndHtml;

            result.RegisterFileUploadOptions("ImageUrl.FileName", new ControlFileUploadOptions
            {
                AllowedExtensions = "jpg,jpeg,png,gif"
            });
            result.AddAction().HasText(this.T("Clear")).HasUrl(this.Url.Action("Edit", RouteData.Values.Merge(new { id = 0 }))).HasButtonStyle(ButtonStyle.Success);
            result.AddAction().HasText(this.T("Back")).HasUrl(this.Url.Action("Index")).HasButtonStyle(ButtonStyle.Danger);

            result.RegisterExternalDataSource(x => x.CategoryId, y => BindCategories());

            return(result);
        }
Esempio n. 8
0
        /// <summary>
        /// Создадим новый баннер
        /// </summary>
        /// <param name="id">Идентификатор</param>
        /// <param name="item">Модель баннера</param>
        /// <returns></returns>
        public override bool createBanner(Guid id, BannersModel item)
        {
            using (var db = new CMSdb(_context))
            {
                using (var tran = db.BeginTransaction())
                {
                    var query = db.content_bannerss.Where(w => w.id.Equals(id));

                    if (!query.Any())
                    {
                        var queryMaxSort = db.content_bannerss
                                           .Where(w => w.f_site.Equals(item.Site))
                                           .Where(w => w.f_section.Equals(item.Section))
                                           .Select(s => s.n_sort);

                        int maxSort = queryMaxSort.Any() ? queryMaxSort.Max() + 1 : 1;

                        db.content_bannerss
                        .Value(v => v.id, id)
                        .Value(v => v.f_site, item.Site)
                        .Value(v => v.c_title, item.Title)
                        .Value(v => v.c_photo, item.Photo != null ? item.Photo.Url : null)
                        .Value(v => v.c_url, item.Url)
                        .Value(v => v.c_text, item.Text)
                        .Value(v => v.d_date, item.Date)
                        .Value(v => v.n_sort, maxSort)
                        .Value(v => v.b_disabled, item.Disabled)
                        .Value(v => v.f_section, item.Section)
                        .Insert();


                        var siteId = currentSiteId();
                        //var siteBanners = new content_content_link()
                        //{
                        //    id = Guid.NewGuid(),
                        //    f_content = id,
                        //    f_content_type = ContentType.BANNER.ToString().ToLower(),
                        //    f_link = siteId,
                        //    f_link_type = ContentLinkType.SITE.ToString().ToLower(),
                        //    b_origin = true
                        //};
                        //db.Insert(siteBanners);

                        // логирование
                        var log = new LogModel()
                        {
                            Site     = _domain,
                            Section  = LogSection.Banners,
                            Action   = LogAction.insert,
                            PageId   = id,
                            PageName = item.Title,
                            UserId   = _currentUserId,
                            IP       = _ip,
                        };
                        insertLog(log);

                        tran.Commit();
                        return(true);
                    }
                }
                return(false);
            }
        }
Esempio n. 9
0
 public abstract bool updateBanner(Guid id, BannersModel item);