public JsonResult Search(SearchGroupViewModel options) { try { var query = _context.Group.Where(x => x.StatusId != GroupStatus.Deleted.Id); if (!string.IsNullOrEmpty(options.word)) { var word = options.word.ToStandardPersian(); query = query.Where(x => x.Title.Contains(word)); } var count = query.Count(); var data = query.OrderByDescending(x => x.Id) .Skip(options.page * options.count) .Take(options.count) .Select(x => new ResponseSearchGroupViewModel() { id = x.Id, title = x.Title, order = x.Order, statusId = x.StatusId, statusTitle = x.Status.PersianTitle, }).ToList(); return(SuccessSearch(data, options.page, options.count, count)); } catch (Exception ex) { return(ServerError(ex)); } }
public IActionResult SearchGroup(SearchGroupViewModel searchGroupViewModel) { if (ModelState.IsValid) { var existingGroup = _GroupStore.GetGroupByName(searchGroupViewModel.Groupname); if (existingGroup is null) { ViewBag.Message = "Group Does not Exist"; } else { var GroupViewModel = new List <GroupResultViewModel>(); var GroupResult = new GroupResultViewModel() { Groupname = existingGroup.Name, GroupId = existingGroup.Id, CreatedOn = existingGroup.CreationDate, CreatedBy = _GroupStore.GetGroupOwner(existingGroup.Id).Username }; GroupViewModel.Add(GroupResult); searchGroupViewModel.Groups = GroupViewModel; } } return(View(searchGroupViewModel)); }