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); }
public Category Post([FromBody] Category catPost) => categoryRepository.AddCategory(new Category { CategoryId = catPost.CategoryId, CategoryName = catPost.CategoryName });
public IActionResult Post(Category category) { var currentUserProfile = GetCurrentUserProfile(); _categoryRepo.AddCategory(category); return(CreatedAtAction(nameof(Get), new { id = category.Id }, category)); }
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()); }
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()); }
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; }
public int AddCategory(NewCategoryVm model) { var category = _mapper.Map <Category>(model); _categoryRepo.AddCategory(category); return(category.Id); }
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); }
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))); }
public IActionResult Create(Category model) { if (ModelState.IsValid) { categoryRepository.AddCategory(model); return(RedirectToAction("List")); } return(View(model)); }
public IActionResult Create(Category entity) { if (ModelState.IsValid) { catrepository.AddCategory(entity); return(RedirectToAction("List")); } return(View(entity)); }
public bool AddCategory(Category category) { if (!_db.Categories.Where(c => c.CategoryName.ToLower() == category.CategoryName.ToLower()).Any()) { _db.AddCategory(category); return(true); } return(false); }
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))); }
public async Task <IActionResult> Create(Category category) { if (ModelState.IsValid) { await repo.AddCategory(category); return(RedirectToAction(nameof(Index))); } return(View(category)); }
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)); }
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)); }
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)); }
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); }
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)); }
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()); } }