示例#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);
                }
            }
        }
示例#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 });
        }
示例#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());
        }
示例#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);
        }
示例#5
0
        public async Task AddCategory(GetAllCategoriesblogViewItem newCategory)
        {
            Category category = new Category();

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

            await _categoriesRepository.SaveChanges();
        }
示例#6
0
 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);
        }
示例#9
0
 private void SetCommands()
 {
     CreateCategoryAction = new RelayCommand(async() => {
         var category = new Category {
             Name = CateggoryNameText
         };
         await _categoriesRepository.Add(category);
         _navigationService.GoBack();
     }, () => true);
 }
示例#10
0
文件: Seed.cs 项目: jbyall/looking2
        public static void SeedCategories(ICategoriesRepository _categoriesRepo)
        {
            _categoriesRepo.Db.DropCollection("categories");
            var newCategories = GetSeedCategories();

            foreach (var item in newCategories)
            {
                _categoriesRepo.Add(item);
            }
        }
示例#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));
        }
示例#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));
        }
示例#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));
        }
示例#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)));
 }
示例#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));
        }
示例#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"));
        }
示例#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));
            }
        }
示例#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"));
        }
示例#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);
 }
示例#22
0
 public ApiResponseBase Put([FromBody] ApiCategory product)
 {
     _repo.Add(product);
     return(new ApiResponseBase());
 }
示例#23
0
 public void Add(Categories category)
 {
     _repCategories.Add(category);
 }
示例#24
0
 public EventCategory Post([FromBody] EventCategory category)
 {
     return(_repository.Add(category));
 }
示例#25
0
 public void Save(Categories category)
 {
     _categoryRepository.Add(category);
     _unitOfWork.Complete();
 }
示例#26
0
 public CategoriesViewModel Add(CategoriesViewModel categories)
 {
     _categoriesRepository.Add(Mapper.Map <Categories>(categories));
     return(categories);
 }
示例#27
0
 public async Task AddAndSave(Category category)
 {
     _categRepo.Add(category);
     await _categRepo.Save();
 }