Ejemplo n.º 1
0
        public async Task <IActionResult> Create(Production model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create"));
            }

            await _productionRepository.AddAsync(model);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public override async Task <int> HandleCommand(InsertProductionCommand request, CancellationToken cancellationToken)
        {
            var id = 0;

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

            if (company == null)
            {
                throw new BusinessException("Common.NoPermission");
            }

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        var gTIN = await gTINService.InsertOrUpdateGTINAsync(company.Id, request.Model.GTIN, request.LoginSession);

                        request.Model.GTINId = gTIN.Id;

                        request.Model.PartnerId    = company.Id;
                        request.Model.CreatedDate  = DateTime.Now;
                        request.Model.CreatedBy    = request.LoginSession.Id;
                        request.Model.ModifiedDate = DateTime.Now;
                        request.Model.ModifiedBy   = request.LoginSession.Id;

                        id = await productionRepository.AddAsync(request.Model);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (id > 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try { trans.Rollback(); } catch { }
                        }
                    }
                }
            }

            return(id);
        }