private void SalvarCargos(IEnumerable <Cargo> listaCargo)
 {
     foreach (var itens in listaCargo)
     {
         _cargoRepository.Add(itens);
     }
 }
        public async Task Add(CargoInsertDTO cargo)
        {
            Cargo cargoInsert = new Cargo();

            cargoInsert.Nome = cargo.Nome;

            await repository.Add(cargoInsert);
        }
Beispiel #3
0
 public Int32 Create(CARGO item, LOG log)
 {
     using (DbContextTransaction transaction = Db.Database.BeginTransaction(IsolationLevel.ReadCommitted))
     {
         try
         {
             _logRepository.Add(log);
             _baseRepository.Add(item);
             transaction.Commit();
             return(0);
         }
         catch (Exception ex)
         {
             transaction.Rollback();
             throw ex;
         }
     }
 }
Beispiel #4
0
 public Cargo Add(Cargo cargo)
 {
     try
     {
         return(repository.Add(cargo));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
        public CargoDTO Add(CargoDTO cargoDTO)
        {
            var cargo = cargoDTO.ToModel();

            cargo.Id      = IdentityGenerator.NewSequentialGuid();
            cargo.Created = DateTime.UtcNow;
            if (cargoDTO.Category != null)
            {
                cargo.Category = _CategoryRepository.Get(cargoDTO.Category.Id);
            }
            else
            {
                cargo.Category = null;
            }

            if (cargo.Name.IsNullOrBlank())
            {
                throw new DefinedException(CommonMessageResources.Name_Empty);
            }

            if (_Repository.Exists(cargo))
            {
                throw new DataExistsException(string.Format(BaseMessagesResources.Cargo_Exists_WithValue, cargo.Name));
            }

            var ruleName = CommonMessageResources.SerialNumberRule_Cargo;
            var snRule   = SerialNumberRuleQuerier.FindBy(ruleName);

            if (snRule == null)
            {
                throw new DataNotFoundException(string.Format(BaseMessagesResources.SerialNumberRule_NotExists_WithValue, ruleName));
            }
            cargo.Sn = SerialNumberGenerator.GetSerialNumber(snRule.Prefix, snRule.UseDateNumber, snRule.NumberLength);

            _Repository.Add(cargo);

            #region 操作日志

            var cargoDto = cargo.ToDto();

            OperateRecorder.RecordOperation(cargoDto.Sn,
                                            BaseMessagesResources.Add_Cargo,
                                            cargoDto.GetOperationLog());

            #endregion

            //commit the unit of work
            _Repository.UnitOfWork.Commit();

            return(cargo.ToDto());
        }
        public Task Handle(CadastrarCargoCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Task.CompletedTask);
            }

            var cargo = new Cargo(Guid.NewGuid(), message.Nome, message.GrupoPoolId);

            _cargoRepository.Add(cargo);

            if (Commit())
            {
                Bus.RaiseEvent(new CargoRegisteredEvent(cargo.Id, cargo.Nome, cargo.GrupoPoolId));
                return(Task.CompletedTask);
            }

            return(Task.CompletedTask);
        }
 public Cargo Add(Cargo obj)
 {
     return(_cargoRepository.Add(obj));
 }