Exemplo n.º 1
0
        public ActionResult Delete(string[] ids)
        {
            try
            {
                if (ids.IsAny())
                {
                    var idTest = from id in ids select id;
                    var aa     = idTest.FirstOrDefault();

                    var genericControls =
                        from id in ids
                        select _gCService.GetById(int.Parse(id));

                    _gCService.BatchDelete(genericControls);

                    //Delete localize
                    for (var i = 0; i < ids.Length; i++)
                    {
                        var localizedProperties
                            = _localizedPropertyService.GetByEntityId(int.Parse(ids[i]));

                        _localizedPropertyService.BatchDelete(localizedProperties);
                    }
                }
            }
            catch (Exception ex)
            {
                LogText.Log(string.Concat("GenericControl --> Delete: ", ex.Message));
                ModelState.AddModelError("", ex.Message);
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(string[] ids)
        {
            try
            {
                if (ids.Length != 0)
                {
                    var genericControls =
                        from id in ids
                        select _genericControlService.GetById(int.Parse(id));

                    _genericControlService.BatchDelete(genericControls);

                    //Delete localize
                    for (var i = 0; i < ids.Length; i++)
                    {
                        var ieLocalizedProperty
                            = _localizedPropertyService.GetByEntityId(int.Parse(ids[i]));
                        _localizedPropertyService.BatchDelete(ieLocalizedProperty);
                    }
                }
            }
            catch (Exception exception1)
            {
                var exception = exception1;
                ExtentionUtils.Log(string.Concat("ServerGenericControl.Delete: ", exception.Message));
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult Index(int page = 1, string keywords = "")
        {
            ViewBag.Keywords = keywords;
            var sortingPagingBuilder = new SortingPagingBuilder
            {
                Keywords = keywords,
                Sorts    = new SortBuilder
                {
                    ColumnName  = "CreatedDate",
                    ColumnOrder = SortBuilder.SortOrder.Descending
                }
            };
            var paging = new Paging
            {
                PageNumber  = page,
                PageSize    = PageSize,
                TotalRecord = 0
            };
            var list = _genericControlValueService.PagedList(sortingPagingBuilder, paging).ToList();

            list.ForEach(item => item.GenericControl = _genericControlService.GetById(item.GenericControlId));
            if (list.IsAny())
            {
                var pageInfo = new Helper.PageInfo(CommonHelper.PageSize, page, paging.TotalRecord, i => Url.Action("Index", new { page = i, keywords }));
                ViewBag.PageInfo = pageInfo;
            }
            return(View(list));
        }
Exemplo n.º 4
0
        public ActionResult Edit(GenericControlViewModel model, string ReturnUrl)
        {
            ActionResult action;

            try
            {
                if (!base.ModelState.IsValid)
                {
                    String messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                                  .Select(v => v.ErrorMessage + " " + v.Exception));
                    base.ModelState.AddModelError("", messages);
                    return(base.View(model));
                }
                else
                {
                    GenericControl objGenericControl = _genericControlService.GetById(model.Id);

                    List <MenuLink> lstMenuLink = new List <MenuLink>();
                    List <int>      lstMenuId   = new List <int>();

                    string menuLink = this.Request["MenuLink"];
                    if (!string.IsNullOrEmpty(menuLink))
                    {
                        foreach (var item in menuLink.Split(new char[] { ',' }).ToList <string>())
                        {
                            int menuId = int.Parse(item);
                            lstMenuId.Add(menuId);

                            lstMenuLink.Add(_menuLinkService.GetById(menuId, isCache: false));
                        }

                        if (lstMenuId.IsAny())
                        {
                            (from x in objGenericControl.MenuLinks
                             where !lstMenuId.Contains(x.Id)
                             select x).ToList <MenuLink>()
                            .ForEach((MenuLink m) =>
                                     objGenericControl.MenuLinks.Remove(m)
                                     );
                        }
                    }
                    objGenericControl.MenuLinks = lstMenuLink;

                    GenericControl modelMap = Mapper.Map <GenericControlViewModel, GenericControl>(model);
                    this._genericControlService.Update(objGenericControl);


                    //Update Localized
                    foreach (var localized in model.Locales)
                    {
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Name, localized.Name, localized.LanguageId);
                        _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId);
                    }

                    base.Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.UpdateSuccess, FormUI.GenericControl)));
                    if (!base.Url.IsLocalUrl(ReturnUrl) || ReturnUrl.Length <= 1 || !ReturnUrl.StartsWith("/") || ReturnUrl.StartsWith("//") || ReturnUrl.StartsWith("/\\"))
                    {
                        action = base.RedirectToAction("Index");
                    }
                    else
                    {
                        action = this.Redirect(ReturnUrl);
                    }
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                ExtentionUtils.Log(string.Concat("GenericControl.Create: ", exception.Message));
                return(base.View(model));
            }
            return(action);
        }