private async void btnCreate_Click(object sender, EventArgs e) { var categories = new Category() { CategoryName = txtName.Text, Image = WindowsFormsUtilities.WindowsImageConverter.ConvertImage(pictureBox1.Image) }; var validation = WindowsFormValidationContext.Validated <Category>(categories); if (validation.Item1) { categoriesRepository.Add(categories); var result = await categoriesRepository.SaveChangesAsync(); if (result > 0) { MessageBox.Show("The Category has been Added", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } else { foreach (var item in validation.Item2) { MessageBox.Show(item.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private async void Initialize(ICategoriesRepository catsRepo, IAccountsRepository accsRepo) { await catsRepo.Add(new Category { Name = "Transfer" }); await catsRepo.Add(new Category { Name = "Drinks" }); await catsRepo.Add(new Category { Name = "Weed" }); await catsRepo.Add(new Category { Name = "Junk food" }); await catsRepo.Add(new Category { Name = "Salary" }); await accsRepo.Add(new Account { Name = "Cash", Currency = "rub", IsCash = true }); await accsRepo.Add(new Account { Name = "Credit card", Currency = "usd", IsCash = false }); }
//[Route("AddCategory")] public async Task <IActionResult> PostCategory(Category model) { if (ModelState.IsValid) { try { var categId = await CategoriesRepository.Add(model); if (categId == true) { return(Ok(categId)); } else { return(NotFound()); } } catch (Exception) { return(BadRequest()); } } return(BadRequest()); }
public object Post(Category added) { object json; try { Category posted = repository.Add(added); json = new { total = 1, data = posted, success = true }; } catch (Exception ex) { LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message); json = new { message = ex.Message, success = false }; }; return(json); }
public async Task AddCategory(GetAllCategoriesblogViewItem newCategory) { Category category = new Category(); category.CategoryName = newCategory.Category; await _categoriesRepository.Add(category); await _categoriesRepository.SaveChanges(); }
public IActionResult Post([FromBody] Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _categoryRepository.Add(category); return(StatusCode(StatusCodes.Status201Created)); }
public async Task <CategoryModel> Add(UpsertCategoryModel model) { var category = _mapper.Map <Category>(model); await _repository.Add(category); await _repository.SaveChanges(); return(_mapper.Map <CategoryModel>(category)); }
public async Task <Guid> Handle(CreateCategoryCommand request, CancellationToken cancellationToken) { var category = new Category(request.Name, request.Color, request.CreatedBy); await _categoriesRepository.Add(category); await _categoriesRepository.UnitOfWork.SaveEntitiesAsync(); return(category.Id); }
private void SetCommands() { CreateCategoryAction = new RelayCommand(async() => { var category = new Category { Name = CateggoryNameText }; await _categoriesRepository.Add(category); _navigationService.GoBack(); }, () => true); }
public static void SeedCategories(ICategoriesRepository _categoriesRepo) { _categoriesRepo.Db.DropCollection("categories"); var newCategories = GetSeedCategories(); foreach (var item in newCategories) { _categoriesRepo.Add(item); } }
public IActionResult Categories([FromBody] CategoryItem item) { //var item = Newtonsoft.Json.JsonConvert.DeserializeObject<CategoryItem>(data); var result = _categoriesRepository.Add(item); if (result == null) { return(NotFound()); } return(Ok(result)); }
public async Task <ActionResult <CategoryOutputModel> > CreateCategory(CategoryInputModel categoryInputModel) { var categoryToInsert = _mapper.Map <Domain.Models.Category>(categoryInputModel); _categoriesRepository.Add(categoryToInsert); await _categoriesRepository.SaveChangesAsync(); var categoryOutput = _mapper.Map <Dtos.CategoryOutputModel>(categoryToInsert); return(CreatedAtRoute("GetCategory", new { categoryId = categoryToInsert.Id }, categoryOutput)); }
public void Handle(AddCategoryCommand command) { if (!command.IsValid()) { RaiseValidationErrors(command); return; } var category = Category.Create(command.Name); categoriesRepository.Add(category); }
public IActionResult PostCategory([FromBody] Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } category.CreatedDateTime = DateTime.Now; _categoriesRepository.Add(category); return(CreatedAtAction("GetCategory", new { id = category.Id }, category)); }
public PartialViewResult AddCategory(string newCategory) { if (!ModelState.IsValid) { return(PartialView("CategoriesPartial", categoriesRepository.Categories.Select(x => x.CategoryName).OrderBy(x => x))); } if (newCategory != null) { categoriesRepository.Add(newCategory); } return(PartialView("CategoriesPartial", categoriesRepository.Categories.Select(x => x.CategoryName).OrderBy(x => x))); }
public async Task <IHttpActionResult> PostCategory(Categories category) { if (await _Repo.CategoryExists(category.CategoryName, category.TransactionType)) { return(BadRequest("Kategori sudah pernah dibuat")); } category.CreatedDate = DateTime.Now; category.UpdatedDate = DateTime.Now; await _Repo.Add(category); return(StatusCode(HttpStatusCode.OK)); }
public void AddCategory(CategoryDTO categoryDTO) { //check if this category already exists if (_categoryRepository.GetCategoryByName(categoryDTO.Name) != null) { throw new ValidationException("This category name already exists"); } //map db entity to DTO var category = _mapper.Map <Category>(categoryDTO); //add category to DB _categoryRepository.Add(category); }
public IActionResult AddCategory([FromBody] CategoryDto categoryData) { if (string.IsNullOrEmpty(categoryData.Title)) { return(BadRequest("Title missing")); } Category newCategory = new Category { Title = categoryData.Title, }; _categoriesRepository.Add(newCategory); return(Ok("Category added successfully")); }
/// <summary> /// Додає категорію /// </summary> /// <param name="categoryDto">Екземпляр категорії</param> public void AddCategory(CategoriesDtoModel categoryDto) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <CategoriesDtoModel, CategoriesModel>()).CreateMapper(); CategoriesModel category = mapper.Map <CategoriesModel>(categoryDto); var results = categoriesValidator.Validate(category); if (results.IsValid) { categoriesRepository.Add(category); } else { throw new Exception("Помилка валідації категорії: " + Environment.NewLine + ValidationResultsHelper.GetValidationErrors(results)); } }
public IResult Save(CategoriesDto categoriesDto) { CategoriesEntity categories = new CategoriesEntity(categoriesDto.Name); if (_categoriesRepository.Get(categories) != null) { return(new ValidateResult(categories, false, "Categoria informada já existe")); } categories.Validate(); if (categories.Invalid) { return(new ValidateResult(categories.Notifications, false, "Problemas ao cadastrar a Categoria")); } _categoriesRepository.Add(categories); return(new ValidateResult(categories, true, "Categoria cadastrada com sucessso")); }
public int?SaveCategories(CategoriesSaveRequest request) { if (request.Id != null) { var categories = _categoriesRepository.GetSingleNoneDeleted(x => x.Id == request.Id); //update if (categories != null) { categories.Name = request.Name; categories.Description = request.Description; categories.ModifiedDate = Constants.GetDateNow(); categories.ModifiedBy = Constants.GetUserId(); _categoriesRepository.Update(categories); _categoriesRepository.Commit(); } if (categories != null) { return(categories.Id); } } else { //add new var newCat = new Categories { Name = request.Name, Description = request.Description, CreatedBy = Constants.GetUserId(), ModifiedBy = Constants.GetUserId(), CreatedDate = Constants.GetDateNow(), ModifiedDate = Constants.GetDateNow() }; _categoriesRepository.Add(newCat); _categoriesRepository.Commit(); return(newCat.Id); } return(null); }
public ApiResponseBase Put([FromBody] ApiCategory product) { _repo.Add(product); return(new ApiResponseBase()); }
public void Add(Categories category) { _repCategories.Add(category); }
public EventCategory Post([FromBody] EventCategory category) { return(_repository.Add(category)); }
public void Save(Categories category) { _categoryRepository.Add(category); _unitOfWork.Complete(); }
public CategoriesViewModel Add(CategoriesViewModel categories) { _categoriesRepository.Add(Mapper.Map <Categories>(categories)); return(categories); }
public async Task AddAndSave(Category category) { _categRepo.Add(category); await _categRepo.Save(); }