Example #1
0
        public async Task SeedCategories()
        {
            if ((await _categoryRepo.GetCategoriesAsync()).Count > 0)
            {
                return;
            }

            var category = new Category
            {
                Title       = "Sport",
                Description = "For sports new and debates",
            };
            await _categoryRepo.AddCategory(category);

            category = new Category
            {
                Title       = "Politics",
                Description = "Politics"
            };
            await _categoryRepo.AddCategory(category);

            category = new Category
            {
                Title       = "Relationship & Marriage",
                Description = "Realationship & Marriage"
            };
            await _categoryRepo.AddCategory(category);

            category = new Category
            {
                Title       = "Career",
                Description = "Career"
            };
            await _categoryRepo.AddCategory(category);
        }
Example #2
0
        public Category Post([FromBody] Category catPost) =>

        categoryRepository.AddCategory(new Category
        {
            CategoryId   = catPost.CategoryId,
            CategoryName = catPost.CategoryName
        });
Example #3
0
        public IActionResult Post(Category category)
        {
            var currentUserProfile = GetCurrentUserProfile();

            _categoryRepo.AddCategory(category);
            return(CreatedAtAction(nameof(Get), new { id = category.Id }, category));
        }
Example #4
0
        public IActionResult AddCategory(CategoryDto categoryDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var getCategories = categoryRepository.GetCategories().ToList();

            foreach (var category in getCategories)
            {
                if (category.CategoryId.Split("_")[0] == (categoryDto.CategoryId))
                {
                    return(BadRequest(new { repeatedId = "CategoryId has repeated" }));
                }
            }

            var cultures = options.Value.SupportedCultures;

            foreach (var culture in cultures)
            {
                var category = new Category
                {
                    CategoryId   = categoryDto.CategoryId + "_" + culture.Name,
                    CategoryName = categoryDto.CategoryName,
                };
                categoryRepository.AddCategory(category);
            }
            uow.Complete();

            return(Ok());
        }
Example #5
0
 public void AddCategory(Category category)
 {
     if (category != null)
     {
         repository.AddCategory(category);
     }
 }
        public async Task <IActionResult> AddCategory([FromBody] AppCategory model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var addedCategory = await categoryRepo.AddCategory(model);

                    if (addedCategory != null)
                    {
                        return(Ok(addedCategory));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                catch (Exception excp)
                {
                    return(BadRequest(excp));
                }
            }

            return(BadRequest());
        }
Example #7
0
        private void _modalService_OnClose(ModalResult result)
        {
            if (!result.Cancelled)
            {
                CategoryModel updated = (CategoryModel)result.Data;
                if (currentAction == ActionState.Adding)
                {
                    _categoryRepository.AddCategory(updated);
                }
                else if (currentAction == ActionState.Editing)
                {
                    _categoryRepository.EditCategory(updated);
                }
                else
                {
                    try
                    {
                        _categoryRepository.DeleteCategory(updated);
                    }
                    catch (Exception ex)
                    {
                        #warning Pobrac MessageBox z CPEm
                        //_modalService.Show<MessageBox>
                    }
                }

                CategoryList = new List <CategoryModel>(_categoryRepository.GetAll());
            }
            //Show(MatToastType.Success);
            _modalService.OnClose -= _modalService_OnClose;
        }
Example #8
0
        public int AddCategory(NewCategoryVm model)
        {
            var category = _mapper.Map <Category>(model);

            _categoryRepo.AddCategory(category);
            return(category.Id);
        }
Example #9
0
        public async Task <Response <string> > AddCategory([FromBody] CategoryViewModel categoryViewModel)
        {
            var response = new Response <string>();

            if (categoryViewModel == null)
            {
                response.Code = "401";
                response.Msg  = "添加分类失败";
                return(response);
            }

            var category = new Category
            {
                CategoryID   = categoryViewModel.CategoryId,
                ParentID     = categoryViewModel.ParentId,
                CategoryName = categoryViewModel.CategoryName,
                ViewOrder    = categoryViewModel.ViewOrder,
                Description  = categoryViewModel.Description
            };
            await _category.AddCategory(category);

            response.Code = "200";
            response.Msg  = "添加分类成功";
            return(response);
        }
        public IActionResult SubmitCategory(CategoryViewModel categoryViewModel)
        {
            var category            = Mapper.Map <Category>(categoryViewModel);
            var categoriesViewModel = new CategoriesViewModel();

            category.Name = category.Name.Trim();
            if (category.Name == "")
            {
                throw new Exception("Du skal navngive din kategori");
            }

            if (categoryViewModel.Id != Guid.Empty)
            {
                _categoryRepository.UpdateCategory(category, _userManager.GetUserId(HttpContext.User));
                categoriesViewModel.PageAction = Enums.CategoriesPageAction.EditedCategory;
            }
            else
            {
                _categoryRepository.AddCategory(category, _userManager.GetUserId(HttpContext.User));
                categoriesViewModel.PageAction = Enums.CategoriesPageAction.AddedCategory;
            }

            ViewData["Title"] = "Kategorier";

            return(RedirectToAction("Categories", "Home", categoriesViewModel));
        }
        /// <summary>
        /// Method to add a new Category
        /// </summary>
        /// <param name="category"></param>
        public void AddCategory(CategoryVM category)
        {
            var cat = new Category {
                CategoryName = category.CategoryName
            };

            _categoryRepository.AddCategory(cat);
        }
Example #12
0
 public void InsertCategory(Category category)
 {
     if (category == null)
     {
         return;
     }
     _category.AddCategory(category);
     _cacheService.AddCache(category, category.ID);
 }
 public ActionResult AddCategory(Category category)
 {
     if (!ModelState.IsValid)
     {
         return(View(category));
     }
     _categoryRepository.AddCategory(category);
     return(RedirectToAction(nameof(List)));
 }
Example #14
0
 public IActionResult Create(Category model)
 {
     if (ModelState.IsValid)
     {
         categoryRepository.AddCategory(model);
         return(RedirectToAction("List"));
     }
     return(View(model));
 }
Example #15
0
 public IActionResult Create(Category entity)
 {
     if (ModelState.IsValid)
     {
         catrepository.AddCategory(entity);
         return(RedirectToAction("List"));
     }
     return(View(entity));
 }
Example #16
0
 public bool AddCategory(Category category)
 {
     if (!_db.Categories.Where(c => c.CategoryName.ToLower() == category.CategoryName.ToLower()).Any())
     {
         _db.AddCategory(category);
         return(true);
     }
     return(false);
 }
Example #17
0
        public async Task <Message> Execute(Message message,
                                            TelegramBotClient client)
        {
            _chatId = message.Chat.Id;
            _msg    = message.Text;
            _usrId  = message.From.Id;
            _client = client;

            if (!_userAccountRepository.GetUser(_usrId,
                                                out UserAccount userAccount))
            {
                throw new UserNotFoundException(_msg, _usrId);
            }

            bool   isMounthly = false;
            string cleanCmd;

            Regex regex = new Regex(_rgxString);
            Match match = regex.Match(_msg);

            if (match.Success)
            {
                isMounthly = true;
                cleanCmd   = _msg.Substring(0, _msg.Length - 1);
            }
            else
            {
                cleanCmd = _msg;
            }


            string categoryName = cleanCmd.Split(" ")[0];

            _categoryRepository.AddCategory(
                new Category
            {
                CategoryName = categoryName,
                CategoryId   =
                    _categoryRepository.Categories
                    .Where(c => c.Author.UserId == _usrId)
                    .Select(c => c.CategoryId)
                    .OrderByDescending(catId => catId)
                    .FirstOrDefault() + 1,
                Description = cleanCmd,
                IsBasic     = false,
                Author      =
                    _userAccountRepository.Accounts
                    .Where(u => u.UserId == _usrId)
                    //TODO: FirstOrDefault / First?
                    .FirstOrDefault(),
                IsMounthly = isMounthly
            }, userAccount);

            return(await _client.SendTextMessageAsync(_chatId,
                                                      string.Format(SimpleTxtResponse.AddCategory, categoryName)));
        }
Example #18
0
        public async Task <IActionResult> Create(Category category)
        {
            if (ModelState.IsValid)
            {
                await repo.AddCategory(category);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Example #19
0
        public IActionResult CreateCategory([FromBody] CategoryDto category)
        {
            var categoryEntity = _mapper.Map <Category>(category);

            _categoryRepository.AddCategory(categoryEntity);

            var categoryToReturn = _mapper.Map <CategoryDto>(categoryEntity);

            return(CreatedAtRoute("GetCategory", new { id = category.Id }, categoryToReturn));
        }
Example #20
0
 public IActionResult AddCategory(ViewCategory viewCategory)
 {
     if (viewCategory.Name != null)
     {
         categoryRepository.AddCategory(new Category {
             Name = viewCategory.Name
         });
     }
     return(RedirectToAction("Index", "Home"));
 }
 public IActionResult Create(Category category)
 {
     if (ModelState.IsValid)
     {
         _categoryRepository.AddCategory(category);
         _categoryRepository.Save();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
Example #22
0
 public async Task <Category> AddCategory(Category category)
 {
     try
     {
         return(await _categoryRepository.AddCategory(category));
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }
        public IActionResult Post(Category category)
        {
            var currentUserProfile = GetCurrentUserProfile();

            if (currentUserProfile.UserTypeId != 1)
            {
                return(Unauthorized());
            }
            _categoryRepo.AddCategory(category);
            return(CreatedAtAction(nameof(Get), new { id = category.Id }, category));
        }
        public IActionResult Create(Category entitiy)
        {
            if (ModelState.IsValid)
            {
                _categoryRepository.AddCategory(entitiy);
                TempData["message"] = Messages.CategoryCreated;
                return(RedirectToAction("List"));
            }

            return(View(entitiy));
        }
Example #25
0
        public async Task <IActionResult> Create([FromForm] Category category)
        {
            if (ModelState.IsValid)
            {
                await _categoryRepository.AddCategory(category);

                return(RedirectToAction(nameof(Index)));
            }

            return(View(category));
        }
        public ActionResult <Category> AddCategory(CategoryDTO dto)
        {
            Category c = new Category {
                Name = dto.Name
            };

            _categoryRepository.AddCategory(c);
            _categoryRepository.SaveChanges();

            return(c);
        }
Example #27
0
 public ActionResult Create(Category category)
 {
     try
     {
         _categoryRepo.AddCategory(category);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View(category));
     }
 }
        public async Task <IActionResult> Create(CategoryViewModel model)
        {
            var category = _mapper.Map <Category>(model);

            _repository.AddCategory(category);

            if (await _repository.SaveChangesAsync())
            {
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Example #29
0
 public IActionResult Add(Category entity)
 {
     if (ModelState.IsValid)
     {
         repositorycategory.AddCategory(entity);
         return(RedirectToAction("List"));
     }
     else
     {
         return(View(entity));
     }
 }
 public IActionResult Post(Category category)
 {
     try
     {
         _categoryRepository.AddCategory(category);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(NotFound());
     }
 }