public IActionResult AddCategory(string title, int parentId, string isRootCategory) { //TODO: better validate title if (string.IsNullOrWhiteSpace(title)) { return(RedirectToAction("CatalogManagement")); } //TODO:find a better way to pass checkbox value if (isRootCategory != null && isRootCategory.Equals("on")) { _categoriesRepository.Create(new Category() { Title = title }); } else { _categoriesRepository.Create(new Category() { Title = title, Parent_Id = parentId }); } return(RedirectToAction("CatalogManagement")); }
public IEnumerable <IResult> Save() { IsBusy = true; yield return(new SingleResult { Action = () => { if (IsEditMode) { if (CategoryId.HasValue) { repository.Update(CategoryId.Value, CategoryName.Trim(), SelectedCategoryType); } else { throw new Exception( "Category ID is not specified for \"Update\" operation."); } } else { repository.Create(CategoryName.Trim(), SelectedCategoryType); } } }); IsBusy = false; Close(); }
public async Task <Guid> Store(Category category) { User user = new User(); HttpClient client = new HttpClient(); var req = await client.GetAsync("https://localhost:5001/users/parser"); Task <string> c = req.Content.ReadAsStringAsync(); var res = JsonConvert.DeserializeObject <List <User> >(c.Result); foreach (var g in res) { if (g.Logged == true) { user = new User() { Id = g.Id, Gmail = g.Gmail, Card = g.Card, Cash = g.Cash, FullName = g.FullName, UserImage = g.UserImage, Logged = true, Password = g.Password }; } } category.UserId = user.Id; return(await _categoriesRepository.Create(category)); }
public async Task <IActionResult> Create([Bind("CategoryId,CategoryName,Description,Picture")] Categories categories) { if (ModelState.IsValid) { await _categoriesRepository.Create(categories); return(RedirectToAction(nameof(Index))); } return(View(categories)); }
public ActionResult Create([Bind("Id,Name")] Category category) { if (ModelState.IsValid) { _categoriesRepository.Create(category); //Add(category); return(RedirectToAction("Index")); } return(View(category)); }
public Category CreateCategory(string name, Category root = null) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException(nameof(name)); } if (root == null) //create new root category { var existingRootCategory = _categoriesRepository.GetAllByName(name).FirstOrDefault(x => x.Title == name && !x.Parent_Id.HasValue); if (existingRootCategory != null) { throw new Exception($"Cannot create category. Root category with title '{name}' already exists."); } var newRootCategory = new Category() { Parent_Id = null, Title = name }; _categoriesRepository.Create(newRootCategory); return(_categoriesRepository.GetAllByName(name).FirstOrDefault(x => x.Title == name)); } else { var existingCategory = _categoriesRepository.GetAllByName(name).FirstOrDefault(x => x.Title == name && x.Parent_Id.Value == root.Id); if (existingCategory != null) { throw new Exception($"Cannot create category. Category with title '{name}' and root '{root.Title}' already exists."); } var newCategory = new Category() { Parent_Id = root.Id, Title = name }; _categoriesRepository.Create(newCategory); return(_categoriesRepository.GetAllByName(name).FirstOrDefault(x => x.Title == name && x.Parent_Id.Value == root.Id)); } }
public IActionResult Create(CategoryCreateViewModel model) { if (ModelState.IsValid) { var result = categoriesRepository.Create(new Category() { CategoryName = model.CategoryName }); if (result != null) { return(RedirectToAction("index", "categories")); } } return(View(model)); }
public virtual ActionResult Create(CategoryViewModel model) { if (ModelState.IsValid) { _categoriesRepository.Create(new Category() { Name = model.Name, QuestionnaireId = model.QuestionnaireId }); return(RedirectToAction(MVC.Admin.Categories.List())); } model.SetQuestionnaires(_questionnairesRepository.GetList()); return(View(model)); }
public User Create(User user) { using (var sqlConnection = new SqlConnection(_connectionString)) { sqlConnection.Open(); using (var command = sqlConnection.CreateCommand()) { user.Id = Guid.NewGuid(); command.CommandText = "insert into Users (id, Nickname,Password) values (@id, @name, @Password)"; command.Parameters.AddWithValue("@id", user.Id); command.Parameters.AddWithValue("@name", user.Name); command.Parameters.AddWithValue("@Password", user.Password); command.ExecuteNonQuery(); } _categoriesRepository.Create(user.Id, "Default"); return(user); } }
public async Task <Guid> Store(Category category) { category.UserId = Domain.Constants.Constants.TestUserId; return(await _categoriesRepository.Create(category)); }
public async Task <ActionResult> Post([FromBody] Categories categories) { return(new OkObjectResult(_repo.Create(categories))); }
public Category Create([FromBody] string name, Guid userId) { Logger.Log.Instance.Trace("Создание категории с названием: {0}", name); return(_categoryRepository.Create(userId, name)); }
public async Task Create(CategoryModel model) { await _repository.Create(MapModelToEntity(model)); }