public override async Task <int> HandleCommand(AddCommand request, CancellationToken cancellationToken)
        {
            if ((request.Fertilizer?.CategoryId ?? 0) > 0)
            {
                var category = await fertilizerCategoryQueries.GetById(request.Fertilizer.CategoryId ?? 0);

                if (category == null)
                {
                    throw new BusinessException("Category.NotExisted");
                }
            }

            var rs = -1;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        fertilizerRepository.JoinTransaction(conn, trans);
                        fertilizerQueries.JoinTransaction(conn, trans);

                        if (request.Fertilizer == null)
                        {
                            throw new BusinessException("AddWrongInformation");
                        }

                        request.Fertilizer.Code = await storageQueries.GenarateCodeAsync(StorageKeys.FertilizerCode);

                        request.Fertilizer = CreateBuild(request.Fertilizer, request.LoginSession);
                        var fertilizerId = await fertilizerRepository.Add(request.Fertilizer);

                        rs = 0;
                    }
                    finally
                    {
                        if (rs == 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try
                            {
                                trans.Rollback();
                            }
                            catch { }
                        }
                    }
                }
            }

            return(rs);
        }
        public async Task <IActionResult> Create(FertilizerViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var fertilizer = new Fertilizer
            {
                Id   = model.Id,
                Name = model.Name,
                N    = model.N,
                P    = model.P,
                K    = model.K,
                Ca   = model.Ca,
                Mg   = model.Mg,
                S    = model.S,
                Na   = model.Na,
            };
            await _fertilizerRepository.Add(fertilizer);

            TempData["message"] = "Dodano nowy nawóz!";
            ModelState.Clear();
            return(View());
        }