Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        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 });
        }
Exemplo n.º 3
0
        //[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());
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public async Task AddCategory(GetAllCategoriesblogViewItem newCategory)
        {
            Category category = new Category();

            category.CategoryName = newCategory.Category;
            await _categoriesRepository.Add(category);

            await _categoriesRepository.SaveChanges();
        }
Exemplo n.º 6
0
 public IActionResult Post([FromBody] Category category)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _categoryRepository.Add(category);
     return(StatusCode(StatusCodes.Status201Created));
 }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 9
0
 private void SetCommands()
 {
     CreateCategoryAction = new RelayCommand(async() => {
         var category = new Category {
             Name = CateggoryNameText
         };
         await _categoriesRepository.Add(category);
         _navigationService.GoBack();
     }, () => true);
 }
Exemplo n.º 10
0
        public static void SeedCategories(ICategoriesRepository _categoriesRepo)
        {
            _categoriesRepo.Db.DropCollection("categories");
            var newCategories = GetSeedCategories();

            foreach (var item in newCategories)
            {
                _categoriesRepo.Add(item);
            }
        }
Exemplo n.º 11
0
        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));
        }
Exemplo n.º 12
0
        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));
        }
Exemplo n.º 13
0
        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));
        }
Exemplo n.º 15
0
 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)));
 }
Exemplo n.º 16
0
        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));
        }
Exemplo n.º 17
0
        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"));
        }
Exemplo n.º 19
0
        /// <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));
            }
        }
Exemplo n.º 20
0
        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"));
        }
Exemplo n.º 21
0
 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);
 }
Exemplo n.º 22
0
 public ApiResponseBase Put([FromBody] ApiCategory product)
 {
     _repo.Add(product);
     return(new ApiResponseBase());
 }
Exemplo n.º 23
0
 public void Add(Categories category)
 {
     _repCategories.Add(category);
 }
Exemplo n.º 24
0
 public EventCategory Post([FromBody] EventCategory category)
 {
     return(_repository.Add(category));
 }
Exemplo n.º 25
0
 public void Save(Categories category)
 {
     _categoryRepository.Add(category);
     _unitOfWork.Complete();
 }
Exemplo n.º 26
0
 public CategoriesViewModel Add(CategoriesViewModel categories)
 {
     _categoriesRepository.Add(Mapper.Map <Categories>(categories));
     return(categories);
 }
Exemplo n.º 27
0
 public async Task AddAndSave(Category category)
 {
     _categRepo.Add(category);
     await _categRepo.Save();
 }