Exemplo n.º 1
0
 private DeclarationView ToView(DeclarationFc declaration)
 {
     return(new DeclarationView
     {
         Date = declaration.Date,
         IsArchive = declaration.IsArchive,
         IsCloture = declaration.IsCloture,
         Trimestre = declaration.Trimestre,
         ExerciceId = declaration.ExerciceId,
         Id = declaration.Id,
     });
 }
 public int Create(DeclarationFc declaration)
 {
     using (var con = new SqlConnection(ConnectionString))
     {
         return(con.Query <int>(QueryInsert, new
         {
             declaration.Date,
             declaration.ExerciceId,
             declaration.IsCloture,
             declaration.IsArchive,
             declaration.SocieteId,
             declaration.Trimestre,
         }).SingleOrDefault());
     }
 }
        public int DeclarationCreate(int trimestre)
        {
            // check current societe
            if (Societe == null)
            {
                throw new InvalidOperationException("Societe courante invalide!");
            }
            //check current exercice
            if (Exercice == null)
            {
                throw new InvalidOperationException("Exercice courant invalid!");
            }
            if (Exercice.IsCloturer)
            {
                throw new InvalidOperationException("Exercice est cloturé");
            }

            // check trimestre
            if (trimestre < 1 || trimestre > 4)
            {
                throw new ApplicationException("Trimestre invalide!");
            }


            var exist = _declarationRepository.GetDeclaration(trimestre, Exercice.Id, Societe.Id);

            if (exist != null)
            {
                throw new ApplicationException("Opération invalide! [déclaration existe déja]");
            }

            var declaration = new DeclarationFc
            {
                Trimestre  = trimestre,
                IsCloture  = false,
                ExerciceId = Exercice.Id,
                Date       = DateTime.Now,
                IsArchive  = false,
                SocieteId  = Societe.Id
            };

            return(_declarationRepository.Create(declaration));
        }