public ActionResult Create(int? id)
        {
            var userName = System.Web.HttpContext.Current.User.Identity.Name;
            var user = _systemService.GetUserAndRole(0, userName);
            if (user == null)
            {
                return RedirectToAction("Index", "Login");
            }

            if (user.CategoryR == 0)
            {
                return RedirectToAction("Index", "Home");
            }

            var item = new WAMS_CATEGORY();

            if (id.HasValue)
            {
                item = _service.GetByKey(id.Value);
            }

            var model = new CategoryViewModel
            {
                bCategoryID = item.bCategoryID,
                CategoryCode = item.CategoryCode,
                vCategoryName = item.CategoryCode,
                iType = item.iType,
                Timestamp = item.Timestamp,
                iCreated = item.iCreated,
                dCreated = item.dCreated,
                UserLogin = user,
                Types = new SelectList(_systemService.TypeStockList(), "Id", "Name")
            };
            return View(model);
        }
        public JsonResult Create(CategoryViewModel model)
        {
            if (model.V3 != true)
            {
                return Json(new { result = Constants.UnSuccess });
            }

            return model.Entity.bCategoryID == 0 ? CreateData(model) : EditData(model);
        }
Exemple #3
0
        public CategoryViewModel SearchRecipes(string search, int take, int skip)
        {
            var searchWords = search.Split(' ');
            var viewModel = new CategoryViewModel();
            var searchResult = _unitOfWork.Recipies.Query(_ => _.Name.Contains(search) || _.Tags.Any(x => x.Name.Contains(search)));

            if (!searchResult.Any())
            {
                foreach (var word in searchWords)
                {
                    searchResult = searchResult.Concat(
                        _unitOfWork.Recipies.Query(
                            _ => _.Name.Contains(word) || _.Tags.Any(x => x.Name.Contains(word))));
                }
            }

            var recipes =
                GenerateSearchRecipeViewModels(searchResult.OrderByDescending(_ => _.Rate).Skip(skip).Take(take));

            viewModel.Recipes = recipes;
            viewModel.TotalCount = searchResult.Count();
            viewModel.Name = search;

            return viewModel;
        }
Exemple #4
0
        public CategoryViewModel GetRecipesForCategory(Guid id, int skip, int take)
        {
            var viewModel = new CategoryViewModel();
            if (id == Guid.Empty)
            {
                var uncategoriesedRecipes = _unitOfWork.Recipies.Query(_ => !_.Tags.Any(x => x.IsCategory));
                viewModel.TotalCount = uncategoriesedRecipes.Count();
                viewModel.Recipes =
                    GenerateSearchRecipeViewModels(
                        uncategoriesedRecipes.OrderBy(_ => _.Rate).ThenBy(_ => _.Name).Skip(skip).Take(take));

                viewModel.Name = "Okategoriserade";

                return viewModel;
            }

            var category = _unitOfWork.RecipeTags.Get(_ => _.Id == id);

            viewModel.Name = category.Name;
            viewModel.TotalCount = category.Recipes.Count;
            viewModel.Recipes =
                GenerateSearchRecipeViewModels(
                    category.Recipes.OrderBy(_ => _.Rate).ThenBy(_ => _.Name).Skip(skip).Take(take));

            return viewModel;
        }
Exemple #5
0
        public CategoryViewModel GetMyRecipes(Guid userId, int take, int skip)
        {
            var viewModel = new CategoryViewModel();
            var allRecipes = _unitOfWork.Recipies.Query(_=>_.User.Id == userId);
            var recipes =
                GenerateSearchRecipeViewModels(allRecipes.OrderByDescending(_ => _.Created).Skip(skip).Take(take));

            viewModel.Recipes = recipes;

            return viewModel;
        }
Exemple #6
0
        public CategoryViewModel GetFavorites(Guid userId, int take, int skip)
        {
            var viewModel = new CategoryViewModel();
            var favorites = _unitOfWork.Users.Get(_ => _.Id == userId).Favorites.Select(_=>_.Recipe);
            var recipes =
                GenerateSearchRecipeViewModels(favorites.OrderByDescending(_ => _.Created).Skip(skip).Take(take));

            viewModel.Recipes = recipes;
            viewModel.TotalCount = favorites.Count();

            return viewModel;
        }
Exemple #7
0
        public CategoryViewModel GetAllRecipes(int take, int skip)
        {
            var viewModel = new CategoryViewModel();
            var allRecipes = _unitOfWork.Recipies.GetAll();
            var recipes = GenerateSearchRecipeViewModels(allRecipes.OrderByDescending(_ => _.Rate).Skip(skip).Take(take));

            viewModel.Recipes = recipes;
            viewModel.TotalCount = allRecipes.Count();

            return viewModel;
        }
        private JsonResult EditData(CategoryViewModel model)
        {
            if (model.CheckCode != model.Entity.CategoryCode)
            {
                if (_service.ExistedCode(model.Entity.CategoryCode))
                {
                    return Json(new { result = Constants.DuplicateCode });
                }
            }

            if (model.CheckName != model.Entity.vCategoryName)
            {
                if (_service.ExistedName(model.Entity.vCategoryName))
                {
                    return Json(new { result = Constants.Duplicate });
                }
            }

            var entity = _service.GetByKey(model.Entity.bCategoryID);
            if (!Convert.ToBase64String(model.Entity.Timestamp).Equals(Convert.ToBase64String(entity.Timestamp)))
            {
                return Json(new { result = Constants.DataJustChanged });
            }

            try
            {
                entity.CategoryCode = model.Entity.CategoryCode;
                entity.vCategoryName = model.Entity.vCategoryName;
                entity.iType = model.Entity.iType;
                entity.iModified = model.LoginId;
                entity.dModified = DateTime.Now;
                _service.Update(entity);

                return Json(new { result = Constants.Success });
            }
            catch (Exception e)
            {
                Log.Error("Update Category!", e);
                return Json(new { result = Constants.UnSuccess });
            }
        }
        private JsonResult CreateData(CategoryViewModel model)
        {
            if (_service.ExistedCode(model.Entity.CategoryCode))
            {
                return Json(new { result = Constants.DuplicateCode });
            }

            if (_service.ExistedName(model.Entity.vCategoryName))
            {
                return Json(new { result = Constants.Duplicate });
            }

            try
            {
                model.Entity.iEnable = true;
                model.Entity.iCreated = model.LoginId;
                model.Entity.dCreated = DateTime.Now;
                _service.Insert(model.Entity);

                return Json(new { result = Constants.Success });
            }
            catch (Exception e)
            {
                Log.Error("Create New Category!", e);
                return Json(new { result = Constants.UnSuccess });
            }
        }
        public ActionResult LoadData(int page, int size, string code, string name, int type, string enable)
        {
            var userName = System.Web.HttpContext.Current.User.Identity.Name;
            var totalRecord = _service.ListConditionCount(page, size, code, name, type, enable);
            var totalTemp = Convert.ToDecimal(totalRecord) / Convert.ToDecimal(size);
            var totalPages = Convert.ToInt32(Math.Ceiling(totalTemp));
            var model = new CategoryViewModel
            {
                UserLogin = _systemService.GetUserAndRole(0, userName),
                ListEntity = _service.ListCondition(page, size, code, name, type, enable),
                TotalRecords = Convert.ToInt32(totalRecord),
                TotalPages = totalPages,
                CurrentPage = page,
                PageSize = size
            };

            return PartialView("_CategoryPartial", model);
        }
 public ActionResult Index()
 {
     var userName = System.Web.HttpContext.Current.User.Identity.Name;
     var user = this._systemService.GetUserAndRole(0, userName);
     if (user == null) return RedirectToAction("Index", "Login");
     if (user.CategoryR == 0) return RedirectToAction("Index", "Home");
     var model = new CategoryViewModel
                     {
                         UserLogin = user,
                         Types = new SelectList(_systemService.TypeStockList(), "Id", "Name")
                     };
     return View(model);
 }
Exemple #12
0
        public ActionResult Show(string slug, int? p)
        {
            using (UnitOfWorkManager.NewUnitOfWork())
            {
                // Get the category
                var category = _categoryService.GetBySlugWithSubCategories(slug);

                // Allowed Categories for this user
                var allowedCategories = _categoryService.GetAllowedCategories(UsersRole);

                // Set the page index
                var pageIndex = p ?? 1;

                // check the user has permission to this category
                var permissions = RoleService.GetPermissions(category.Category, UsersRole);

                if (!permissions[SiteConstants.Instance.PermissionDenyAccess].IsTicked)
                {

                    var topics = _topicService.GetPagedTopicsByCategory(pageIndex,
                                                                        SettingsService.GetSettings().TopicsPerPage,
                                                                        int.MaxValue, category.Category.Id);

                    var topicViewModels = ViewModelMapping.CreateTopicViewModels(topics.ToList(), RoleService, UsersRole, LoggedOnReadOnlyUser, allowedCategories, SettingsService.GetSettings());

                    // Create the main view model for the category
                    var viewModel = new CategoryViewModel
                        {
                            Permissions = permissions,
                            Topics = topicViewModels,
                            Category = category.Category,
                            PageIndex = pageIndex,
                            TotalCount = topics.TotalCount,
                            TotalPages = topics.TotalPages,
                            User = LoggedOnReadOnlyUser,
                            IsSubscribed = UserIsAuthenticated && (_categoryNotificationService.GetByUserAndCategory(LoggedOnReadOnlyUser, category.Category).Any())
                        };

                    // If there are subcategories then add then with their permissions
                    if (category.SubCategories.Any())
                    {
                        var subCatViewModel = new CategoryListViewModel
                            {
                                AllPermissionSets = new Dictionary<Category, PermissionSet>()
                            };
                        foreach (var subCategory in category.SubCategories)
                        {
                            var permissionSet = RoleService.GetPermissions(subCategory, UsersRole);
                            subCatViewModel.AllPermissionSets.Add(subCategory, permissionSet);
                        }
                        viewModel.SubCategories = subCatViewModel;
                    }

                    return View(viewModel);
                }

                return ErrorToHomePage(LocalizationService.GetResourceString("Errors.NoPermission"));
            }
        }
Exemple #13
0
        public PartialViewResult GetSubscribedCategories()
        {
            var viewModel = new List<CategoryViewModel>();
            using (UnitOfWorkManager.NewUnitOfWork())
            {
                var categories = LoggedOnReadOnlyUser.CategoryNotifications.Select(x => x.Category);
                foreach (var category in categories)
                {
                    var permissionSet = RoleService.GetPermissions(category, UsersRole);
                    var topicCount = category.Topics.Count;
                    var latestTopicInCategory = category.Topics.OrderByDescending(x => x.LastPost.DateCreated).FirstOrDefault();
                    var postCount = (category.Topics.SelectMany(x => x.Posts).Count() - 1);
                    var model = new CategoryViewModel
                    {
                        Category = category,
                        LatestTopic = latestTopicInCategory,
                        Permissions = permissionSet,
                        PostCount = postCount,
                        TopicCount = topicCount,
                        ShowUnSubscribedLink = true
                    };
                    viewModel.Add(model);
                }
            }

            return PartialView(viewModel);
        }