public string Save(Anuidade a) { ArgumentsValidator.RaiseExceptionOfInvalidArguments( RaiseException.IfTrue(a.Exercicio == 0, "Exercício não informado") ); Anuidade _a = new Anuidade { AnuidadeId = a.AnuidadeId, Exercicio = a.Exercicio, DtVencimento = a.DtVencimento, DtInicioVigencia = a.DtInicioVigencia, DtTerminoVigencia = a.DtTerminoVigencia, CobrancaLiberada = a.CobrancaLiberada, DtCobrancaLiberada = a.DtCobrancaLiberada, DtCadastro = a.DtCadastro, Ativo = a.Ativo }; try { if (_a.AnuidadeId == 0) { return(_anuidadeService.Insert(_a)); } else { return(_anuidadeService.Update(a.AnuidadeId, _a)); } } catch (Exception ex) { throw ex; } }
public Advertisment GetAdvertismentById(int advertismentId) { ArgumentsValidator.Validate(nameof(advertismentId), advertismentId); return(_adverismentRepository .GetAdvertismentById(advertismentId)); }
/// <summary> /// Provides an option to update an existing advertisement if user is the owner of the advert /// </summary> /// <param name="advertisment">The advertisement.<seealso cref="Advertisment" /> </param> public void UpdateAdvertisment(Advertisment advertisment) { // Validate arguments ArgumentsValidator.Validate(nameof(advertisment), advertisment); ArgumentsValidator.Validate(nameof(advertisment.AdvertismentId), advertisment.AdvertismentId); Advertisment advert = GetAdvertismentById(advertisment.AdvertismentId.Value); if (advert == null) { throw new ArgumentException("Advertisement not found"); } advert.AdvertismentName = advertisment.AdvertismentName; advert.Category = advertisment.Category; advert.AdvertismentDescription = advertisment.AdvertismentDescription; advert.IsBuyNow = advertisment.IsBuyNow; advert.IsAuction = advertisment.IsAuction; advert.IsPromoted = advertisment.IsPromoted; if (advert.IsBuyNow) { advert.BuyNowPrice = advertisment.BuyNowPrice; } if (advert.IsAuction) { advert.CurrentPrice = advertisment.CurrentPrice; } // update DB with pending changes _context.SaveChanges(); }
public void Validate_InvalidFirstArgs_True() { string[] args = { "compressTest", _inputPath, _outputPath }; var result = ArgumentsValidator.Validate(args); Assert.IsFalse(result); }
public void Validate_ExcelentArgs_True() { string[] args = { "compress", _inputPath, _outputPath }; var result = ArgumentsValidator.Validate(args); Assert.IsTrue(result); }
public ActionResult <List <UserMessages> > GetUserMessagesByAdvertismentId(int advertId, string currentUserId) { try { ArgumentsValidator.Validate(nameof(currentUserId), currentUserId); if (advertId < 1) { throw new ArgumentException( MessagingConstants.MessageArgumentWrongValue(nameof(advertId), advertId)); } var response = _messagingService.GetUserMessagesByAdvertismentId(advertId, currentUserId); return(StatusCode(200, response)); } catch (ArgumentNullException) { return(StatusCode(400)); } catch (ArgumentException) { return(StatusCode(400)); } catch (Exception) { return(StatusCode(500)); } }
public Advertisment GetAdvertismentByUserAndId(string userId, int advertId) { ArgumentsValidator.Validate(nameof(userId), userId); return(_context.Advertisment .FirstOrDefault(a => a.AdvertismentId == advertId && a.UserId == userId)); }
public string RessetPasswordByEMail(string email) { ArgumentsValidator.RaiseExceptionOfInvalidArguments( RaiseException.IfNotEmail(email, "Atenção: E-Mail inválido") ); return(_userProfileService.RessetPasswordByEMail(email)); }
public Advertisment GetAdvertimentByUserAndName(string userId, string advertName) { ArgumentsValidator.Validate(nameof(userId), userId); ArgumentsValidator.Validate(nameof(advertName), userId); return(_context.Advertisment .FirstOrDefault(a => a.AdvertismentName == advertName && a.UserId == userId)); }
public void Validate_InvalidPathArgs_True() { _outputPath = "test/test.gz"; string[] args = { "compress", _inputPath, _outputPath }; var result = ArgumentsValidator.Validate(args); Assert.IsFalse(result); }
public UserProfile LoginUser(UserProfileLogin userProfileLogin) { ArgumentsValidator.RaiseExceptionOfInvalidArguments( RaiseException.IfNotEmail(userProfileLogin.EMail, "Atenção: E-Mail inválido"), RaiseException.IfNullOrEmpty(userProfileLogin.PasswordHash, "Atenção: Senha inválida") ); return(_userProfileService.LoginUser(userProfileLogin)); }
public UserProfile Login(string email, string password) { ArgumentsValidator.RaiseExceptionOfInvalidArguments( RaiseException.IfNotEmail(email, "Atenção: E-Mail inválido"), RaiseException.IfNullOrEmpty(password, "Atenção: Senha inválida") ); return(_userProfileService.Login(email, password)); }
public ArgumentsValidatorTests() { var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { ExistentFile, new MockFileData("the spider input") } }); _validator = new ArgumentsValidator(fileSystem); }
public IEnumerable <Advertisment> GetAdvertismentsByUserCategoryDateRange(string userId, string categoryId, string expression, DateTime?dateFrom, DateTime?dateTo) { //ArgumentsValidator.Validate(nameof(userId), userId); ArgumentsValidator.Validate(nameof(categoryId), categoryId); return(_adverismentRepository.GetAdvertismentsByUserCategoryDateRange(userId, categoryId, expression, dateFrom, dateTo)); }
public void ObterListaDeExecoesSemLancar() { List <Exception> result = ArgumentsValidator.GetExceptionList( RaiseException.IfNull(null, "object is required"), RaiseException.IfNotEmail("email_invalid", "email invalid") ); Assert.IsNotNull(result, "object required"); Assert.IsTrue(result.Count == 2, "There should be two exceptions"); }
public void ObterListaDeMensagensDasExcecoes() { List <string> result = ArgumentsValidator.GetMessagesFromExceptions( RaiseException.IfNull(null, "object is required"), RaiseException.IfNotEmail("email_invalid", "email invalid") ); Assert.IsNotNull(result, "object required"); Assert.IsTrue(result.Count == 2, "There should be two exceptions"); }
public string Save(Isencao i) { ArgumentsValidator.RaiseExceptionOfInvalidArguments( RaiseException.IfNullOrEmpty(i.Descricao, "Descrição não informada"), RaiseException.IfTrue(i.DtAta == DateTime.MinValue, "Data não informada"), RaiseException.IfNull(i.DtAta, "Data não informada - Nula"), RaiseException.IfTrue(i.AnoEvento == 0, "Ano da Isencão não informada") ); if (i.TipoIsencao.Equals("1")) { ArgumentsValidator.RaiseExceptionOfInvalidArguments( RaiseException.IfTrue(i.EventoId == 0, "Evento não informado"), RaiseException.IfNull(i.EventoId, "Evento não informado") ); } if (i.TipoIsencao.Equals("2")) { ArgumentsValidator.RaiseExceptionOfInvalidArguments( RaiseException.IfTrue(i.AnuidadeId == 0, "Anuidade não informada"), RaiseException.IfNull(i.AnuidadeId, "Anuidade não informada") ); } Isencao _i = new Isencao { IsencaoId = i.IsencaoId, AnuidadeId = i.AnuidadeId, EventoId = i.EventoId, Descricao = i.Descricao, DtAta = i.DtAta, AnoEvento = i.AnoEvento, TipoIsencao = i.TipoIsencao, Ativo = i.Ativo }; try { if (_i.IsencaoId == 0) { return(_isencaoService.Insert(_i)); } else { return(_isencaoService.Update(i.IsencaoId, _i)); } } catch (Exception ex) { throw ex; } }
public void LancarUnicaExcecaoComMensagensDoGrupoDeExcecoes() { try { ArgumentsValidator.RaiseExceptionOfInvalidArguments( RaiseException.IfNull(null, "object is required"), RaiseException.IfNotEmail("email_invalid", "email invalid") ); } catch (Exception ex) { Assert.IsTrue(ex.Message.Contains("object is required") && ex.Message.Contains("email invalid"), "There should be two exceptions"); } }
/// <summary> /// Updates and existing advertisment /// </summary> /// <param name="saveModel">The save model <seealso cref="AdvertismentSaveModel"/></param> public void UpdateAdvertisment(AdvertismentSaveModel saveModel) { try { ArgumentsValidator.Validate(nameof(saveModel), saveModel); ArgumentsValidator.Validate(nameof(saveModel.AdvertismentName), saveModel.AdvertismentName); string requesterId = _userService.GetUserIdForUserNameAsync(saveModel.UserName).Result; ArgumentsValidator.Validate(nameof(requesterId), requesterId); /** * Check for existing advert name for user requesting operation */ Advertisment existingAdvertisement = _adverismentRepository.GetAdvertismentByUserAndId(requesterId, saveModel.AdvertismentId.Value); if (existingAdvertisement == null) { throw new Exception("No advertisement found"); } existingAdvertisement.AdvertismentId = existingAdvertisement.AdvertismentId; existingAdvertisement.AdvertismentName = saveModel.AdvertismentName; existingAdvertisement.AdvertismentDescription = saveModel.Description; existingAdvertisement.InitialPrice = saveModel.InitialPrice; existingAdvertisement.IsAuction = saveModel.IsAuction; existingAdvertisement.IsBuyNow = saveModel.IsBuyNow; existingAdvertisement.IsPromoted = saveModel.IsPromoted; existingAdvertisement.BuyNowPrice = saveModel.BuyNowPrice; existingAdvertisement.CurrentPrice = saveModel.CurrentPrice; existingAdvertisement.CreatedDateTime = saveModel.CreatedDateTime; existingAdvertisement.CategoryId = saveModel.CategoryId; existingAdvertisement.Status = saveModel.Status; existingAdvertisement.UserId = requesterId; _adverismentRepository.UpdateAdvertisment(existingAdvertisement); } catch (DbUpdateException ex) { Log.Warning(ex, AdvertismentConstants.CANNOT_UPDATE_ADVERT); throw; } catch (Exception ex) { Log.Error(ex, ex.Message); throw; } }
public ActionResult AcknowledgeNotification(int notificationId, int messageId) { try { ArgumentsValidator.Validate(nameof(notificationId), notificationId); _notifyService.AcknowledgeNotification(notificationId); _messagingService.AcknowledgeMessage(messageId); } catch (Exception ex) { Log.Error(ex, ex.Message); } return(StatusCode(200)); }
public ActionResult GetAdvertismentsCount(string userId, int?categoryId, string expression = null) { ArgumentsValidator.Validate(userId, nameof(userId)); long count; try { count = _advertismentService.GetAdvertimentsCount(userId, categoryId, expression); } catch (Exception) { return(StatusCode(500)); } return(StatusCode(200, count)); }
public void LancarUnicaExcecaoComUnicaMensagemDoGrupoDeExcecoes() { try { bool existe = true; ArgumentsValidator.RaiseExceptionOfInvalidArguments("Dados inválidos", RaiseException.IfTrue(existe), RaiseException.IfNotEmail("paulo.com.br") ); } catch (Exception ex) { Assert.IsTrue(ex.Message.Contains("Dados inválidos"), "There should be two exceptions"); } }
public ActionResult <UserContactInfo> GetAvailableContactsForOwner(int advertId, string ownerId) { try { ArgumentsValidator.Validate(nameof(ownerId), ownerId); var result = _messagingService.GetAvailableContactsForOwner(advertId, ownerId).Result; return(StatusCode(200, result)); } catch (ArgumentNullException) { return(StatusCode(400)); } catch (Exception) { return(StatusCode(500)); } }
public ActionResult <List <UserMessages> > GetAdvertMessagesBetweenOwnerAndUser(int advertId, string ownerId, string targetUserId) { try { ArgumentsValidator.Validate(nameof(ownerId), ownerId); ArgumentsValidator.Validate(nameof(targetUserId), targetUserId); var result = _messagingService.GetAdvertMessagesBetweenOwnerAndUser(advertId, ownerId, targetUserId); return(StatusCode(200, result)); } catch (ArgumentNullException) { return(StatusCode(400)); } catch (Exception) { return(StatusCode(500)); } }
public string SaveEventoDao(EventoDao e) { ArgumentsValidator.RaiseExceptionOfInvalidArguments( RaiseException.IfNullOrEmpty(e.Titulo, "Título não informado"), RaiseException.IfNullOrEmpty(e.Descricao, "Descrição não informada"), RaiseException.IfTrue(DateTime.Equals(e.DtInicio, DateTime.MinValue), "Data de Início não informada"), RaiseException.IfTrue(DateTime.Equals(e.DtTermino, DateTime.MinValue), "Data de Término não informada"), RaiseException.IfNullOrEmpty(e.TipoEvento, "Tipo de Evento não informado") ); EventoDao _e = new EventoDao() { EventoId = e.EventoId, Titulo = Functions.AjustaTamanhoString(e.Titulo, 100), Descricao = Functions.AjustaTamanhoString(e.Descricao, 2000), Codigo = Functions.AjustaTamanhoString(e.Codigo, 60), DtInicio = e.DtInicio, DtTermino = e.DtTermino, DtTerminoInscricao = e.DtTerminoInscricao, TipoEvento = e.TipoEvento, AceitaIsencaoAta = e.AceitaIsencaoAta, NomeFoto = e.NomeFoto, Ativo = e.Ativo, TiposPublicosValoresDao = e.TiposPublicosValoresDao }; try { if (_e.EventoId == 0) { return(_eventoService.InsertEventoDao(_e)); } else { return(_eventoService.UpdateEventoDao(e.EventoId, _e)); } } catch (Exception ex) { throw ex; } }
public ActionResult GetAdvertisments(AdvertismentSearchModel searchModel) { try { List <Advertisment> advertisments = new List <Advertisment>(); ArgumentsValidator.Validate(nameof(searchModel), searchModel); // do not validate as this is optional //ArgumentsValidator.Validate(nameof(searchModel.UserId), searchModel.UserId); if (!searchModel.CategoryId.HasValue) { advertisments = _advertismentService.GetAdvertisments(searchModel.Expression, searchModel.UserId) .ToList(); } if (searchModel.CategoryId.HasValue) { advertisments = _advertismentService .GetAdvertismentsByUserCategoryDateRange(searchModel.UserId, searchModel.CategoryId.Value.ToString(), searchModel.Expression, searchModel.StartDate, searchModel.EndDate) .ToList(); } return(StatusCode(200, AdvertHelper.TranslateToResponseObject(advertisments))); } catch (ArgumentException ex) { Log.Error(ex, AdvertismentConstants.ARGUMENT_NULL); return(StatusCode(400)); } catch (DbUpdateException) { return(new StatusCodeResult(507)); } catch (Exception) { return(new StatusCodeResult(500)); } }
public string Save(Colaborador c) { ArgumentsValidator.RaiseExceptionOfInvalidArguments( RaiseException.IfNullOrEmpty(c.Nome, "Nome do Colaborador não informado"), RaiseException.IfNotEmail(c.EMail, "E-Mail inválido"), RaiseException.IfNullOrEmpty(c.NrCelular, "NrCelular não informado"), RaiseException.IfEqualsZero(c.PerfilId, "Perfil não informado") ); Colaborador _c = new Colaborador() { ColaboradorId = c.ColaboradorId, PessoaId = c.PessoaId, Nome = Functions.AjustaTamanhoString(c.Nome, 100), EMail = Functions.AjustaTamanhoString(c.EMail, 100), NomeFoto = Functions.AjustaTamanhoString(c.NomeFoto, 100), Sexo = c.Sexo, DtNascimento = c.DtNascimento, NrCelular = Functions.AjustaTamanhoString(c.NrCelular, 15), PasswordHash = Functions.AjustaTamanhoString(c.PasswordHash, 100), PerfilId = c.PerfilId, Ativo = c.Ativo }; try { if (_c.PessoaId == 0) { return(_colaboradorService.Insert(_c)); } else { return(_colaboradorService.Update(c.PessoaId, _c)); } } catch (Exception ex) { throw ex; } }
public string Save(Atc a) { ArgumentsValidator.RaiseExceptionOfInvalidArguments( RaiseException.IfNullOrEmpty(a.Nome, "Nome da ATC não informado"), RaiseException.IfNullOrEmpty(a.NomePres, "Nome do Presidente não informado") ); Atc _a = new Atc() { AtcId = a.AtcId, Nome = Functions.AjustaTamanhoString(a.Nome, 100), UF = Functions.AjustaTamanhoString(a.UF, 2), NomePres = Functions.AjustaTamanhoString(a.NomePres, 100), NomeVPres = Functions.AjustaTamanhoString(a.NomeVPres, 100), NomePSec = Functions.AjustaTamanhoString(a.NomePSec, 100), NomeSSec = Functions.AjustaTamanhoString(a.NomeSSec, 100), NomePTes = Functions.AjustaTamanhoString(a.NomePTes, 100), NomeSTes = Functions.AjustaTamanhoString(a.NomeSTes, 100), Site = Functions.AjustaTamanhoString(a.Site, 100), SiteDiretoria = Functions.AjustaTamanhoString(a.SiteDiretoria, 100), Ativo = a.Ativo, Codigo = a.Codigo }; try { if (_a.AtcId == 0) { return(_atcService.Insert(_a)); } else { return(_atcService.Update(a.AtcId, _a)); } } catch (Exception ex) { throw ex; } }
public string Save(UserProfile p) { ArgumentsValidator.RaiseExceptionOfInvalidArguments( RaiseException.IfNullOrEmpty(p.Nome, "Nome não informado"), RaiseException.IfNotEmail(p.EMail, "E-Mail inválido"), RaiseException.IfNullOrEmpty(p.NrCelular, "NrCelular não informado") ); UserProfile _p = new UserProfile() { PessoaId = p.PessoaId, Nome = Functions.AjustaTamanhoString(p.Nome, 100), EMail = Functions.AjustaTamanhoString(p.EMail, 100), NomeFoto = Functions.AjustaTamanhoString(p.NomeFoto, 100), Sexo = p.Sexo, NrCelular = Functions.AjustaTamanhoString(p.NrCelular, 15), PasswordHash = Functions.AjustaTamanhoString(p.PasswordHash, 100), PasswordHashReturned = Functions.AjustaTamanhoString(p.PasswordHashReturned, 100) }; return(_userProfileService.Save(p)); }
public void LancarExcecaoIndividualCasoAsColecoesNaoTenhamItemDentro() { string mensagem = "Não há itens na coleção"; List <string> lista = new List <string>(); int[] numeros = new int[] { }; string[] nomes = new string[] { }; try { List <string> mgs = ArgumentsValidator.GetMessagesFromExceptions( RaiseException.IfCollectionEmpty(lista, mensagem), RaiseException.IfCollectionEmpty(numeros, mensagem), RaiseException.IfCollectionEmpty(nomes, mensagem)); Assert.IsTrue(mgs.Count == 3, "As coleções estao nulas."); } catch (Exception ex) { throw ex; } }
public void Setup() { _fileHelper = MockRepository.GenerateMock<IContentHelper>(); _sut = new ArgumentsValidator(_fileHelper); }