Пример #1
0
        public async Task <IActionResult> Edit(EditProductionViewModel model)
        {
            if (ModelState == null)
            {
                return(View("Edit"));
            }
            await _productionRepository.UpdateAsync(model.Production);

            return(RedirectToAction("Index"));
        }
Пример #2
0
        public override async Task <int> HandleCommand(DeleteProductionCommand request, CancellationToken cancellationToken)
        {
            Production production = null;

            if (request.Model == 0)
            {
                throw new BusinessException("Production.NotSelected");
            }
            else
            {
                production = await productionQueries.GetByIdAsync(request.Model);

                if (production == null)
                {
                    throw new BusinessException("Production.NotSelected");
                }
            }

            var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id);

            if (company == null || production.PartnerId != company.Id)
            {
                throw new BusinessException("Common.NoPermission");
            }

            var rs = -1;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        production.IsDeleted    = true;
                        production.ModifiedDate = DateTime.Now;
                        production.ModifiedBy   = request.LoginSession.Id;

                        if (await productionRepository.UpdateAsync(production) > 0)
                        {
                            rs = 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (rs == 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try { trans.Rollback(); } catch { }
                        }
                    }
                }
            }

            return(rs);
        }