Example #1
0
        public async Task <IActionResult> Edit(int id, [Bind("CategoryId,ParentCategoryId,CategoryName,Uri,PictureUri,Description,Id")] CategoryViewModels category)
        {
            if (id != category.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //Aynı anda Hem AnaCategory hem ParentCategory insert edilemez.
                    if (category.CategoryId == 0 && category.ParentCategoryId == 0)
                    {
                        return(RedirectToAction(nameof(Index)));
                    }
                    var entity = _mapper.Map <CategoryViewModels, Category>(category);
                    await _categoryService.UpdateCagetory(entity);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Example #2
0
        public IViewComponentResult Invoke()
        {
            var categoryViewModels = new CategoryViewModels();

            if (!_caches.TryGetValue("categoriesVm", out categoryViewModels))
            {
                if (categoryViewModels == null)
                {
                    var categories = _categoryRepository.Categories().ToList();

                    foreach (var category in categories)
                    {
                        category.SummaryBook = _categoryRepository.CountBooks(category.Id);
                    }
                    categoryViewModels = new CategoryViewModels
                    {
                        Categories = categories
                    };
                }
                var cacheEntryOptions = new MemoryCacheEntryOptions()
                                        .SetSlidingExpiration(TimeSpan.FromMinutes(3));
                _caches.Set("categoriesVm", categoryViewModels, cacheEntryOptions);
            }



            return(View(categoryViewModels));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,CategoryNum,CategoryName,Description,Status")] SnackCategory snackCategory)
        {
            if (id != snackCategory.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(snackCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SnackCategoryExists(snackCategory.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            CategoryViewModels categoryViewModels = new CategoryViewModels()
            {
                AdminName     = GetSession("username"),
                SnackCategory = snackCategory
            };

            return(View(categoryViewModels));
        }
Example #4
0
        private void openExistingPlan(object param)
        {
            SelectedPlan = (PlanViewModel)param;
            CategoryViewModel SelectedItemCategoryViewModel = CategoryViewModels.Where(x => x.Id == SelectedPlan.CategoryId).FirstOrDefault();

            EditorSelectedCategoryViewModel = SelectedItemCategoryViewModel;
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            CategoryViewModels categoryViewModels = await db.CategoryViewModels.FindAsync(id);

            db.CategoryViewModels.Remove(categoryViewModels);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Example #6
0
        private void onPlansAndExpensesSummaryQuerried(GeneralAnswerData generalAnswerData)
        {
            SummariesOfPlansAndExpensesResult = new Collection <SummaryOfPlansAndExpensesResult>(generalAnswerData.SummaryOfPlansAndExpensesResults);

            SummariesOfPlansAndExpensesTitle = "Income and Expenses \n(on category "
                                               + CategoryViewModels.Where(x => x.Id == PlansAndExpensesSelectedCategoryViewModel.Id).FirstOrDefault().CategoryName
                                               + " by granulation " + generalAnswerData.SummaryOfPlansAndExpensesRequest.Granulation
                                               + " in year " + generalAnswerData.SummaryOfPlansAndExpensesRequest.Year
                                               + ")";
        }
        // GET: SnackCategories
        public IActionResult Index()
        {
            CategoryViewModels categoryViewModels = new CategoryViewModels()
            {
                AdminName       = GetSession("username"),
                SnackCategories = _context.SnackCategory.ToList()
            };

            return(View(categoryViewModels));
        }
Example #8
0
        public ActionResult CategoryUpdate(CategoryViewModels data)
        {
            CategoryBussines.GetCategoryResponse request = new CategoryBussines.GetCategoryResponse()
            {
                Category = data.Category
            };
            CategoryBussines.Update.Category(request);

            return(RedirectToAction("CategoryView", new { successful = true, ResultAction = "All Changes was successful" }));
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,CategoryName,CategoryDescription")] CategoryViewModels categoryViewModels)
        {
            if (ModelState.IsValid)
            {
                db.Entry(categoryViewModels).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(categoryViewModels));
        }
Example #10
0
        public async Task <ActionResult> CreateCategory(CategoryViewModels category)
        {
            if (ModelState.IsValid)
            {
                IArticleManager articleManager = new ArticleManager();
                await articleManager.CreateCategory(category.CategoryName, Guid.Parse(Session["userId"].ToString()));

                return(RedirectToAction("categoryList", "Article"));
            }
            ModelState.AddModelError("categoryError", "您的输入有误,请重新输入");
            return(View(category));
        }
        public async Task <ActionResult> Create([Bind(Include = "Id,CategoryName,CategoryDescription")] CategoryViewModels categoryViewModels)
        {
            if (ModelState.IsValid)
            {
                db.CategoryViewModels.Add(categoryViewModels);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(categoryViewModels));
        }
Example #12
0
        public ActionResult CategoryCreate()
        {
            ViewBag.Title   = "New Category";
            ViewBag.Message = "";

            var modal        = new CategoryViewModels();
            var BussinesData = CategoryBussines.Select.GetCategoryToFather();

            modal.CategoryList = BussinesData.CategoryList;
            modal.Error        = new Bussines.Handler.ErrorObject();

            return(PartialView(modal));
        }
        // GET: SnackCategories/Create
        public IActionResult Create()
        {
            long max_category_num = _context.SnackCategory.Max(c => c.CategoryNum);
            long new_category_num = max_category_num + 1;
            CategoryViewModels categoryViewModels = new CategoryViewModels()
            {
                AdminName      = GetSession("username"),
                NewCategoryNum = new_category_num

                                 //SnackCategory = snackCategory
            };

            return(View(categoryViewModels));
        }
        // GET: CategoryViewModels/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CategoryViewModels categoryViewModels = await db.CategoryViewModels.FindAsync(id);

            if (categoryViewModels == null)
            {
                return(HttpNotFound());
            }
            return(View(categoryViewModels));
        }
Example #15
0
        // GET: Category
        #region Views
        public ActionResult CategoryView(bool successful = false, string ResultAction = "")
        {
            ViewBag.Title      = "Category";
            ViewBag.successful = successful;
            ViewBag.Message    = ResultAction;

            var BussinesData = CategoryBussines.Select.GetCategory();
            var model        = new CategoryViewModels();

            model.Error        = BussinesData.Error;
            model.CategoryList = CategoryBussines.Select.CategoryListOrderByFatherAndChild(BussinesData.CategoryList);

            return(View(model));
        }
Example #16
0
 public ActionResult Search(CategoryViewModels model)
 {
     try
     {
         var data = _factory.GetListCategory();
         model.ListCate = data;
     }
     catch (Exception e)
     {
         NSLog.Logger.Error("GetListCategory: ", e);
         return(new HttpStatusCodeResult(400, e.Message));
     }
     return(PartialView("_ListData", model));
 }
Example #17
0
        public async Task <IActionResult> Create([Bind("CategoryId,ParentCategoryId,CategoryName,Uri,PictureUri,Description,Id")] CategoryViewModels category)
        {
            if (ModelState.IsValid)
            {
                //Aynı anda Hem AnaCategory hem ParentCategory insert edilemez.
                if (category.CategoryId == 0 && category.ParentCategoryId == 0)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                var entity = _mapper.Map <CategoryViewModels, Category>(category);
                await _categoryService.AddAsync(entity);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Example #18
0
        public ActionResult Categories()
        {
            var concernId = Convert.ToInt32(Session["ConcernId"]);
            var userId    = Convert.ToInt32(Session["UserId"]);

            if (concernId > 0 && userId > 0)
            {
                var category = _inventorySetting.Categories(concernId);
                CategoryViewModels viewModels = new CategoryViewModels()
                {
                    Categories = category
                };
                return(View(viewModels));
            }
            return(RedirectToAction("Login", "GlobalData", new { Area = "Global" }));
        }
Example #19
0
        public ActionResult CreateCategory([Bind(Exclude = "Badge")] CategoryViewModels category, HttpPostedFileBase badge)
        {
            if (ModelState.IsValid)
            {
                if (badge != null)
                {
                    category.Badge = new byte[badge.ContentLength];
                    badge.InputStream.Read(category.Badge, 0, badge.ContentLength);
                }

                var mapper      = new MapperConfiguration(cfg => cfg.CreateMap <CategoryViewModels, DTOCategory>()).CreateMapper();
                var DTOCategory = mapper.Map <CategoryViewModels, DTOCategory>(category);
                postService.CreateCategoryDTO(DTOCategory);
            }

            return(RedirectToAction("ListOfCategories", "Post"));
        }
        public async Task <IActionResult> Create([Bind("Id,CategoryNum,CategoryName,Description,Status")] SnackCategory snackCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(snackCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            CategoryViewModels categoryViewModels = new CategoryViewModels()
            {
                AdminName     = GetSession("username"),
                SnackCategory = snackCategory
            };

            return(View(categoryViewModels));
        }
Example #21
0
        public ActionResult CategoryUpdate(int id)
        {
            ViewBag.Title   = "Update Category";
            ViewBag.Message = "";
            CategoryBussines.GetCategoryRequest request = new CategoryBussines.GetCategoryRequest()
            {
                CategoryID = id
            };
            Category c     = CategoryBussines.Select.GetCategory(request).Category;
            var      model = new CategoryViewModels()
            {
                Category       = c,
                containerChild = CategoryBussines.Select.ContainerChild(request).IfFather,
                CategoryList   = CategoryBussines.Select.GetCategoryToFather().CategoryList
            };

            return(PartialView(model));
        }
        // GET: SnackCategories/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var snackCategory = await _context.SnackCategory.FindAsync(id);

            if (snackCategory == null)
            {
                return(NotFound());
            }

            CategoryViewModels categoryViewModels = new CategoryViewModels()
            {
                AdminName     = GetSession("username"),
                SnackCategory = snackCategory
            };

            return(View(categoryViewModels));
        }
Example #23
0
        public IViewComponentResult Invoke()
        {
            var categories = new List <Category>();

            if (!_cache.TryGetValue("categoryMenu", out categories))
            {
                if (categories == null)
                {
                    categories = _categoryRepository.Categories().ToList();
                }
                var cacheEntryOptions = new MemoryCacheEntryOptions()
                                        .SetSlidingExpiration(TimeSpan.FromMinutes(3));

                _cache.Set("categoryMenu", categories);
            }
            CategoryViewModels categoryViewModels = new CategoryViewModels
            {
                Categories = categories
            };

            return(View(categoryViewModels));
        }
        // GET: SnackCategories/Details/5
        public IActionResult Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var snackCategory = _context.SnackCategory
                                .FirstOrDefault(m => m.Id == id);

            if (snackCategory == null)
            {
                return(NotFound());
            }

            CategoryViewModels categoryViewModels = new CategoryViewModels()
            {
                AdminName     = GetSession("username"),
                SnackCategory = snackCategory
            };

            return(View(categoryViewModels));
        }
Example #25
0
        private void GetUserData()
        {
            Task.Run(async() =>
            {
                User = await ServiceBus.UserService.GetUserByServerId(UserId);

                var userCvs  = await ServiceBus.UserService.GetUserCvsByServerId(UserId);
                var userInfo = await ServiceBus.UserService.GetUserInfoById(User.UserId);

                Position = userInfo?.Department ?? "?";

                InvokeOnMainThread(() => { UserTechnologyCategoryViewModels.Clear(); });

                var technologyCategoryIds = new Dictionary <string, UserTechnologyCategoryViewModel>();
                foreach (var technologyCvs in userCvs.UserCv.Technologies)
                {
                    if (!technologyCategoryIds.ContainsKey(technologyCvs.Category.Id))
                    {
                        var userTechnologyCategoryViewModel = new UserTechnologyCategoryViewModel
                        {
                            Name = technologyCvs.Category.Name
                        };
                        technologyCategoryIds.Add(technologyCvs.Category.Id, userTechnologyCategoryViewModel);

                        // TODO: Currently replaced with awful approach below
                        InvokeOnMainThread(
                            () => { CategoryViewModels.Add(userTechnologyCategoryViewModel); });
                    }

                    InvokeOnMainThread(() =>
                    {
                        technologyCategoryIds[technologyCvs.Category.Id].UserTechnologyViewModels.Add(
                            new UserTechnologyViewModel(technologyCvs.Name, technologyCvs.Stars));
                    });
                }

                // TODO: Awful approach suggested due to Nested ListViews are poorly supported.
                // TODO: Anyway, UserTechnologyCategoryViewModel has propriate collection of user technologies to create nested binding in future.
                foreach (var userTechnologyCategoryViewModel in technologyCategoryIds.OrderBy(t => t.Value.Name))
                {
                    InvokeOnMainThread(
                        () =>
                    {
                        UserTechnologyCategoryViewModels.Add(userTechnologyCategoryViewModel.Value);
                        foreach (
                            var userTechnologyViewModel in userTechnologyCategoryViewModel
                            .Value
                            .UserTechnologyViewModels
                            .OrderByDescending(i => i.Stars))
                        {
                            UserTechnologyCategoryViewModels.Add(userTechnologyViewModel);
                        }
                    });
                }

                RaisePropertyChanged(() => TechnologiesVisibility);

                foreach (var achievementId in _user.Pdp.AchievementsIds)
                {
                    var achievement       = await ServiceBus.UserService.GetAchievementsById(achievementId);
                    var userAchievementVm = new UserAchievementViewModel
                    {
                        Name     = achievement.Name,
                        Category = achievement.Category.Name,
                        ImageUri = Constants.BaseUrl + achievement.ImageUri
                    };
                    InvokeOnMainThread(() => { Achievements.Add(userAchievementVm); });
                }

                RaisePropertyChanged(() => AchievementsVisibility);

                foreach (var certificationId in _user.Pdp.CertificationsIds)
                {
                    var certification       = await ServiceBus.UserService.GetCertificateByIdAsync(certificationId);
                    var userCertificationVm = new UserCertificationViewModel
                    {
                        Name     = certification.Name,
                        Category = certification.Category.Name,
                        ImageUri = Constants.BaseUrl + certification.ImageUri
                    };
                    InvokeOnMainThread(() => { Certifications.Add(userCertificationVm); });
                }

                RaisePropertyChanged(() => CertificationsVisibility);
            });
        }
Example #26
0
        public ActionResult Index()
        {
            CategoryViewModels model = new CategoryViewModels();

            return(View(model));
        }
Example #27
0
        public object GetAllModerationItems([FromQuery] FeedQuery feedQuery, int user)
        {
            var query = _ctx.ModerationItems.Where(x => !x.Deleted);

            if (user == 1)
            {
                query = query.Where(x => x.UserId == UserId);
            }

            var moderationItems = query
                                  .Include(mi => mi.User)
                                  .Include(x => x.Reviews)
                                  .OrderFeed(feedQuery)
                                  .ToList();

            var targetMapping = new Dictionary <string, object>();

            foreach (var group in moderationItems.GroupBy(x => x.Type))
            {
                var targetIds = group
                                .Select(m => new[] { m.Target, m.Current })
                                .SelectMany(x => x)
                                .Where(x => x > 0)
                                .ToArray();

                if (group.Key == ModerationTypes.Technique)
                {
                    _ctx.Techniques
                    .Where(t => targetIds.Contains(t.Id))
                    .ToList()
                    .ForEach(technique => targetMapping[ModerationTypes.Technique + technique.Id] = TechniqueViewModels.CreateFlat(technique));
                }
                else if (group.Key == ModerationTypes.Category)
                {
                    _ctx.Categories
                    .Where(c => targetIds.Contains(c.Id))
                    .ToList()
                    .ForEach(category => targetMapping[ModerationTypes.Category + category.Id] =
                                 CategoryViewModels.CreateFlat(category));
                }
                else if (group.Key == ModerationTypes.SubCategory)
                {
                    _ctx.SubCategories
                    .Where(sc => targetIds.Contains(sc.Id))
                    .ToList()
                    .ForEach(subcategory => targetMapping[ModerationTypes.SubCategory + subcategory.Id] =
                                 SubCategoryViewModels.CreateFlat(subcategory));
                }
            }

            return(moderationItems.Select(x => new
            {
                x.Id, // Crucial to editing
                x.Current,
                x.Target,
                x.Reason,
                x.Type,

                Updated = x.Updated.ToLocalTime().ToString("HH:mm dd/MM/yyyy"),
                Reviews = x.Reviews.Select(r => r.Status).ToList(),
                User = UserViewModel.CreateFlat(x.User),
                CurrentObject = x.Current > 0 ? targetMapping[x.Type + x.Current] : null,
                TargetObject = x.Target > 0 ? targetMapping[x.Type + x.Target] : null,
            }));
        }
Example #28
0
        public object All([FromQuery] FeedQuery feedQuery, int user)
        {
            var query = _ctx.ModerationItems.Where(x => !x.Deleted);

            if (user == 1)
            {
                query = query.Where(x => x.UserId == UserId);
            }

            var moderationItems = query
                                  .Include(x => x.User)
                                  .Include(x => x.Reviews)
                                  .OrderFeed(feedQuery)
                                  .ToList();

            var targetMapping = new Dictionary <string, object>();

            foreach (var group in moderationItems.GroupBy(x => x.Type))
            {
                var targetIds = group
                                .Select(m => new[] { m.Target, m.Current })
                                .SelectMany(x => x)
                                .Where(x => x > 0)
                                .ToArray();

                if (group.Key == ModerationTypes.Trick)
                {
                    _ctx.Tricks
                    .Where(t => targetIds.Contains(t.Id))
                    .ToList()
                    .ForEach(trick => targetMapping[ModerationTypes.Trick + trick.Id] =
                                 TrickViewModels.CreateFlat(trick));
                }
                else if (group.Key == ModerationTypes.Category)
                {
                    _ctx.Categories
                    .Where(c => targetIds.Contains(c.Id))
                    .ToList()
                    .ForEach(category => targetMapping[ModerationTypes.Category + category.Id] =
                                 CategoryViewModels.CreateFlat(category));
                }
                else if (group.Key == ModerationTypes.Difficulty)
                {
                    _ctx.Difficulties
                    .Where(d => targetIds.Contains(d.Id))
                    .ToList()
                    .ForEach(difficulty => targetMapping[ModerationTypes.Difficulty + difficulty.Id] =
                                 DifficultyViewModels.CreateFlat(difficulty));
                }
            }

            return(moderationItems.Select(x => new
            {
                x.Id,
                x.Current,
                x.Target,
                x.Reason,
                x.Type,
                Updated = x.Updated.ToLocalTime().ToString("HH:mm dd/MM/yyyy"),
                Reviews = x.Reviews.Select(y => y.Status).ToList(),
                User = UserViewModels.CreateFlat(x.User),
                CurrentObject = x.Current > 0 ? targetMapping[x.Type + x.Current] : null,
                TargetObject = x.Target > 0 ? targetMapping[x.Type + x.Target] : null,
            }));
        }