public ActionResult Index(int CategoryID)
        {
            SearchCategoryViewModel model = new SearchCategoryViewModel();

            model.AllCategories = db.Ingredients.ToList();
            ViewBag.CategoryID  = new SelectList(model.AllCategories, "ID", "CategoryName");
            var curries = db.Ingredients.Find(CategoryID);

            return(View(curries.Curries.ToList()));
        }
예제 #2
0
        public async Task <HttpResponseMessage> DeleteCategories([FromBody] SearchCategoryViewModel conditions)
        {
            try
            {
                #region Parameter validate

                // Conditions haven't been initialized.
                if (conditions == null)
                {
                    conditions = new SearchCategoryViewModel();
                    Validate(conditions);
                }

                //Request parameters are invalid
                if (!ModelState.IsValid)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, FindValidationMessage(ModelState, nameof(conditions))));
                }

                #endregion

                #region Record delete

                // Delete categories by using specific conditions.
                var categories = UnitOfWork.RepositoryCategories.Search();
                categories = UnitOfWork.RepositoryCategories.Search(categories, conditions);

                // Delete the list of categories.
                UnitOfWork.RepositoryCategories.Remove(categories);

                // Save changes into database.
                var totalRecords = await UnitOfWork.CommitAsync();

                // No record has been deleted.
                if (totalRecords < 1)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, HttpMessages.CategoryNotFound));
                }

                #endregion

                // Tell the client , deletion is successful.
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception exception)
            {
                _log.Error(exception.Message, exception);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
        //[Route("GetAllCategory")]

        public async Task <IActionResult> GetAllCategory([FromBody] SearchCategoryViewModel viewModel)
        {
            if (viewModel.PageIndex == -1 || viewModel.PageSize == -1)
            {
                return(this.ApiResponse <string>(null, $"{viewModel.PageIndex} or {viewModel.PageSize} can not be -1", ApiResponseCodes.INVALID_REQUEST));
            }

            var result = await _categoryService.GetAllCategory(viewModel);

            if ((result.Code != ApiResponseCodes.OK))
            {
                return(base.ApiResponse <string>(null, result.Description,
                                                 ApiResponseCodes.EXCEPTION, 1));
            }
            if (result.Payload == null)
            {
                return(this.ApiResponse <List <CategoryListViewModel> >(result.Payload, "Record not Found.", ApiResponseCodes.NOT_FOUND));
            }
            return(this.ApiResponse <List <CategoryListViewModel> >(result.Payload, "successful.", ApiResponseCodes.OK));
        }
예제 #4
0
        public static string GetFormattedBreadCrumb(this SearchCategoryViewModel category, IEnumerable <SearchCategoryViewModel> categoryService, string separator = ">>")
        {
            string result = string.Empty;

            if (category.ParentCategoryId == null || category.ParentCategoryId == 0)
            {
                return(category.Name);
            }
            var breadcrumb = categoryService.Where(x => x.Id == category.ParentCategoryId).FirstOrDefault();

            if (breadcrumb == null)
            {
                return(category.Name);
            }
            var categoryName = breadcrumb.Name;

            result = string.Format("{0} {1} {2}", categoryName, separator, category.Name);

            return(result);
        }
예제 #5
0
        public IActionResult SearchByCategory(int id)
        {
            List <Product> products = _temp.GetProducts(id);

            Category category = _temp.GetCategory(id);

            List <Category> categories = _temp.GetCategoryById(Convert.ToInt32(category.ParentId));

            Category parentCategory = _temp.GetCategory(Convert.ToInt32(category.ParentId));

            List <Store> stores = _temp.GetStores(id);

            var viewmodel = new SearchCategoryViewModel();

            viewmodel.FillCategories     = categories;
            viewmodel.FillProducts       = products;
            viewmodel.FillParentCategory = parentCategory;
            viewmodel.FillSelectCategory = category;
            viewmodel.FillStores         = stores;

            return(View(viewmodel));
        }
예제 #6
0
        public JsonResult Search(SearchCategoryViewModel options)
        {
            try
            {
                var query = _context.Category.Where(x => x.StatusId != CategoryStatus.Deleted.Id && x.CategoryTypeId == CategoryType.Product.Id);

                if (!string.IsNullOrEmpty(options.word))
                {
                    var word = options.word.ToStandardPersian();
                    query = query.Where(x => x.TranslationList.Select(y => y.Title).Contains(word));
                }

                if (options.parentId != null && options.parentId > 0)
                {
                    query = query.Where(x => x.ParentId == options.parentId);
                }

                var count = query.Count();

                var data = query.OrderByDescending(x => x.Id)
                           .Skip(options.page * options.count)
                           .Take(options.count)
                           .Select(x => new ResponseSearchCategoryViewModel()
                {
                    id          = x.Id,
                    title       = x.Sku,
                    order       = x.Order,
                    statusId    = x.StatusId,
                    statusTitle = x.Status.PersianTitle
                }).ToList();

                return(SuccessSearch(data, options.page + 1, options.count, count));
            }
            catch (Exception ex)
            {
                return(ServerError(ex));
            }
        }
예제 #7
0
        public ActionResult CategoryTable(string search, int?pageNo)
        {
            //ApplicationDbContext _context= new ApplicationDbContext();
            SearchCategoryViewModel model             = new SearchCategoryViewModel();
            CategoriesHandler       categoriesHandler = new CategoriesHandler();

            model.SearchItem = search;

            pageNo = pageNo.HasValue ? pageNo.Value > 0 ? pageNo.Value : 1 : 1;

            var totalRecord = categoriesHandler.GetCategoryCount(search);

            model.Categories = categoriesHandler.GetAllCategories(search, pageNo.Value);

            //model.Categories = _context.Categories.ToList();

            if (model.Categories != null)
            {
                model.Pager = new Pager(totalRecord, pageNo, 3);
                return(PartialView("_categoryTable", model));
            }
            return(PartialView("_categoryTable", model));
        }
예제 #8
0
        public async Task <ApiResponse <List <CategoryListViewModel> > > GetAllCategory(SearchCategoryViewModel viewModel)
        {
            ApiResponse <List <CategoryListViewModel> > response = new ApiResponse <List <CategoryListViewModel> >();

            try
            {
                var count = UnitOfWork.Repository <Category>().Query().Count(x => !x.IsDeleted);
                Expression <Func <Category, bool> > queryPredicate = (x) => x.Name.Contains(viewModel.FilterBy) ||
                                                                     x.CreatedOn >= viewModel.ToDate || x.CreatedOn <= viewModel.FromDate;

                var result = (await this.GetAllAsync(viewModel.PageIndex, viewModel.PageSize, c => c.Id, queryPredicate, OrderBy.Ascending))
                             .OrderBy(b => b.Id).Select(source => new CategoryListViewModel
                {
                    Name        = source.Name,
                    Description = source.Description,
                    TotalCount  = count,
                    Id          = source.Id.ToString(),
                }).ToList();
                response.Payload     = result;
                response.Code        = ApiResponseCodes.OK;
                response.Description = ApiResponseCodes.OK.ToString();
                return(response);
            }
            catch (Exception ex)
            {
                response.Payload     = null;
                response.Code        = ApiResponseCodes.ERROR;
                response.Description = ex.Message;
                return(response);
            }
        }
예제 #9
0
        public async Task <HttpResponseMessage> InitiatePost([FromBody] InitiatePostViewModel parameters)
        {
            try
            {
                #region Parameters validation

                // Parameters haven't been initialized.
                if (parameters == null)
                {
                    // Initiate the parameter.
                    parameters = new InitiatePostViewModel();
                    Validate(parameters);
                }

                //Request parameters are invalid
                if (!ModelState.IsValid)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
                }

                #endregion

                #region Account identity search

                // Search account from request.
                var account = _identityService.FindAccount(Request.Properties);
                if (account == null)
                {
                    throw new Exception("No account has attached to request");
                }

                #endregion

                #region Category search

                // Search condition build.
                var findCategoryConditions = new SearchCategoryViewModel();
                findCategoryConditions.Id = parameters.CategoryIndex;

                // Search the first match category in the database.
                var categories = _unitOfWork.RepositoryCategories.Search();
                var category   =
                    await _unitOfWork.RepositoryCategories.Search(categories, findCategoryConditions)
                    .FirstOrDefaultAsync();

                if (category == null)
                {
                    _log.Error($"No category (Id: {parameters.CategoryIndex}) is found in database.");
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, HttpMessages.CategoryNotFound));
                }

                #endregion

                #region Post initialization

                // Initiate new post.
                var post = new Post();
                post.OwnerIndex    = account.Id;
                post.CategoryIndex = parameters.CategoryIndex;
                post.Title         = parameters.Title;
                post.Body          = parameters.Body;
                post.Created       = _timeService.DateTimeUtcToUnix(DateTime.UtcNow);

                //Add category record
                _unitOfWork.RepositoryPosts.Insert(post);

                // Save changes into database.
                await _unitOfWork.CommitAsync();

                #endregion

                return(Request.CreateResponse(HttpStatusCode.Created, post));
            }
            catch (Exception exception)
            {
                _log.Error(exception.Message, exception);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
예제 #10
0
        /// <summary>
        ///     Search categories by using specific conditions.
        /// </summary>
        /// <param name="categories"></param>
        /// <param name="conditions"></param>
        /// <returns></returns>
        public IQueryable <Category> Search(IQueryable <Category> categories, SearchCategoryViewModel conditions)
        {
            // Id has been defined.
            if (conditions.Id != null)
            {
                categories = categories.Where(x => x.Id == conditions.Id.Value);
            }

            // Creator has been defined.
            if (conditions.CreatorId != null)
            {
                categories = categories.Where(x => x.CreatorId == conditions.CreatorId.Value);
            }

            // Name search condition has been defined.
            if (conditions.Name != null && !string.IsNullOrWhiteSpace(conditions.Name.Value))
            {
                var szName = conditions.Name;
                switch (szName.Mode)
                {
                case TextSearchMode.Contain:
                    categories = categories.Where(x => x.Name.Contains(szName.Value));
                    break;

                case TextSearchMode.Equal:
                    categories = categories.Where(x => x.Name.Equals(szName.Value));
                    break;

                case TextSearchMode.EqualIgnoreCase:
                    categories =
                        categories.Where(x => x.Name.Equals(szName.Value, StringComparison.CurrentCultureIgnoreCase));
                    break;

                case TextSearchMode.StartsWith:
                    categories = categories.Where(x => x.Name.StartsWith(szName.Value));
                    break;

                case TextSearchMode.StartsWithIgnoreCase:
                    categories =
                        categories.Where(
                            x => x.Name.StartsWith(szName.Value, StringComparison.CurrentCultureIgnoreCase));
                    break;

                case TextSearchMode.EndsWith:
                    categories = categories.Where(x => x.Name.EndsWith(szName.Value));
                    break;

                case TextSearchMode.EndsWithIgnoreCase:
                    categories =
                        categories.Where(
                            x => x.Name.EndsWith(szName.Value, StringComparison.CurrentCultureIgnoreCase));
                    break;

                default:
                    categories = categories.Where(x => x.Name.ToLower().Contains(szName.Value.ToLower()));
                    break;
                }
            }

            // CreatedTime time range has been defined.
            if (conditions.CreatedTime != null)
            {
                // Start time is defined.
                if (conditions.CreatedTime.From != null)
                {
                    categories = categories.Where(x => x.CreatedTime >= conditions.CreatedTime.From.Value);
                }

                // End time is defined.
                if (conditions.CreatedTime.To != null)
                {
                    categories = categories.Where(x => x.CreatedTime <= conditions.CreatedTime.To.Value);
                }
            }

            // Last modified time range has been defined.
            if (conditions.LastModifiedTime != null)
            {
                // Start time is defined.
                if (conditions.LastModifiedTime.From != null)
                {
                    categories = categories.Where(x => x.LastModifiedTime >= conditions.LastModifiedTime.From.Value);
                }

                // End time is defined.
                if (conditions.LastModifiedTime.To != null)
                {
                    categories = categories.Where(x => x.LastModifiedTime <= conditions.LastModifiedTime.To.Value);
                }
            }

            return(categories);
        }
예제 #11
0
        public async Task <HttpResponseMessage> InitiateCategory([FromBody] InitiateCategoryViewModel parameters)
        {
            try
            {
                #region Parameters validation

                // Parameters haven't been initialized.
                if (parameters == null)
                {
                    parameters = new InitiateCategoryViewModel();
                    Validate(parameters);
                }

                //Request parameters are invalid
                if (!ModelState.IsValid)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
                }

                #endregion

                #region Account validate

                // Search account information attached in the current request.
                var account = _identityService.FindAccount(Request.Properties);

                if (account == null)
                {
                    throw new Exception("No account information is attached into current request.");
                }

                #endregion

                #region Record duplicate check

                var findCategoryConditions = new SearchCategoryViewModel();
                findCategoryConditions.Name       = new TextSearch();
                findCategoryConditions.Name.Value = parameters.Name;
                findCategoryConditions.Name.Mode  = TextComparision.EqualIgnoreCase;

                // Category has been created before.
                var categories = UnitOfWork.RepositoryCategories.Search();
                var category   = await UnitOfWork.RepositoryCategories.Search(categories, findCategoryConditions).FirstOrDefaultAsync();

                if (category != null)
                {
                    _log.Error($"Category with name : {parameters.Name} has been created before.");
                    return(Request.CreateErrorResponse(HttpStatusCode.Conflict, HttpMessages.CategoryDuplicated));
                }

                #endregion

                #region Record initialization

                // Search current time on system.
                var systemTime = _timeService.DateTimeUtcToUnix(DateTime.UtcNow);

                // Search the id of requester.
                //Initiate new category
                category = new Category();
                category.CreatorIndex = account.Id;
                category.Created      = systemTime;
                category.Name         = parameters.Name;

                //Add category record
                UnitOfWork.RepositoryCategories.Insert(category);

                // Save changes.
                await UnitOfWork.CommitAsync();

                #endregion

                return(Request.CreateResponse(HttpStatusCode.Created, category));
            }
            catch (Exception exception)
            {
                _log.Error(exception.Message, exception);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
예제 #12
0
        public async Task <HttpResponseMessage> FindCategories([FromBody] SearchCategoryViewModel conditions)
        {
            try
            {
                #region Parameters validation

                // Conditions haven't been initialized.
                if (conditions == null)
                {
                    conditions = new SearchCategoryViewModel();
                    Validate(conditions);
                }

                // Parameters are invalid.
                if (!ModelState.IsValid)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest,
                                                  FindValidationMessage(ModelState, nameof(conditions))));
                }

                #endregion

                #region Records search

                // Initiate search result.
                var searchResult = new SearchResult <IList <CategoryViewModel> >();

                // Search all categories.
                var categories = UnitOfWork.RepositoryCategories.Search();
                categories = UnitOfWork.RepositoryCategories.Search(categories, conditions);

                // Search all accounts in the database.
                var accounts = UnitOfWork.RepositoryAccounts.Search();

                var apiCategories = from account in accounts
                                    from category in categories
                                    where account.Id == category.CreatorIndex
                                    select new CategoryViewModel
                {
                    Id      = category.Id,
                    Creator = new AccountViewModel
                    {
                        Id       = account.Id,
                        Email    = account.Email,
                        Nickname = account.Nickname,
                        Status   = account.Status,
                        Joined   = account.Joined
                    },
                    Name         = category.Name,
                    Created      = category.Created,
                    LastModified = category.LastModified
                };

                #endregion

                // Sort the results.
                var sorting = conditions.Sorting;
                apiCategories = UnitOfWork.RepositoryCategories.Sort(apiCategories, sorting.Direction, sorting.Property);

                // Update result.
                searchResult.Total = await apiCategories.CountAsync();

                searchResult.Records = await UnitOfWork.RepositoryCategories.Paginate(apiCategories, conditions.Pagination).ToListAsync();

                return(Request.CreateResponse(HttpStatusCode.OK, searchResult));
            }
            catch (Exception exception)
            {
                _log.Error(exception.Message, exception);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }