コード例 #1
0
 public void AddOrUpdate(Anuncio anuncio)
 {
     try
     {
         dataContext.BeginTransaction();
         if (ValidaAnuncio(anuncio))
         {
             if (anuncio.AnuncioId > 0)
             {
                 Update(anuncio);
             }
             else
             {
                 Add(anuncio);
             }
             dataContext.Commit();
             ResponseService = new ResponseService()
             {
                 Type    = ResponseTypeEnum.Success,
                 Message = "Anúncio cadastrado com sucesso."
             };
         }
     }
     catch (Exception ex)
     {
         dataContext.Rollback();
         ResponseService = new ResponseService()
         {
             Type    = ResponseTypeEnum.Error,
             Message = "Erro ao cadastrar anúncio."
         };
     }
     finally
     {
         dataContext.Finally();
     }
 }
コード例 #2
0
 public bool ValidaAnuncio(Anuncio anuncio)
 {
     ResponseService = new ResponseService();
     if (string.IsNullOrEmpty(anuncio.NomePessoa))
     {
         ResponseService.FieldsInvalids.Add("NomePessoa");
     }
     if (anuncio.VeiculoTipo == VeiculoEnum.None)
     {
         ResponseService.FieldsInvalids.Add("VeiculoTipo");
     }
     if (string.IsNullOrEmpty(anuncio.Modelo))
     {
         ResponseService.FieldsInvalids.Add("Modelo");
     }
     if (anuncio.Bairro == BairroEnum.None)
     {
         ResponseService.FieldsInvalids.Add("Bairro");
     }
     if (string.IsNullOrEmpty(anuncio.Telefone))
     {
         ResponseService.FieldsInvalids.Add("Telefone");
     }
     if (string.IsNullOrEmpty(anuncio.Placa))
     {
         ResponseService.FieldsInvalids.Add("Placa");
     }
     if (ResponseService.FieldsInvalids.Count > 0)
     {
         ResponseService.Message = "Informe os dados corretamente.";
     }
     ResponseService.Type =
         string.IsNullOrEmpty(ResponseService.Message) ?
         ResponseTypeEnum.Success :
         ResponseTypeEnum.Warning;
     return(ResponseService.Type == ResponseTypeEnum.Success);
 }
コード例 #3
0
 public AnuncioService()
 {
     dataContext       = new DataContext();
     ResponseService   = new ResponseService();
     anuncioRepository = new AnuncioRepository();
 }