private BasicAuthenticationDto GetBasicAuthentication(string userName, string password, long?idCompany, long?idApplication, string token) { bool authenticationError = false; BasicAuthenticationDto dtoResultUserAuthentication = new BasicAuthenticationDto(); dtoResultUserAuthentication.AuthenticationCod = Convert.ToInt16(AuthenticationCode.AccessDenied); dtoResultUserAuthentication.MessageAuthentication = "AccessDenied"; if (token != "not apply") { if (this.GetServiceToken() != token) { authenticationError = true; dtoResultUserAuthentication.MessageAuthentication = "AccessDenied"; } } if (String.IsNullOrEmpty(userName) || String.IsNullOrEmpty(password)) { authenticationError = true; dtoResultUserAuthentication.MessageAuthentication = "AccessDenied"; } if (authenticationError == false) { UserApplicationDto dtoUserApplication = new UserApplicationDto(); dtoUserApplication.UserName = userName; dtoUserApplication.UserPassword = password; dtoUserApplication.IdCompany = idCompany; dtoUserApplication.State = true; dtoUserApplication = UserApplicationRepository.GetUserApplication(dtoUserApplication).FirstOrDefault(); if (dtoUserApplication == null) { authenticationError = true; dtoResultUserAuthentication.MessageAuthentication = "AccessDenied"; } else { dtoUserApplication.UserPassword = null; if (dtoUserApplication.EffectiveDate != null && dtoUserApplication.EffectiveDate >= DateTime.Now) { authenticationError = true; dtoResultUserAuthentication.MessageAuthentication = "AccessDenied - Limit Date"; } else { dtoResultUserAuthentication.User = dtoUserApplication; } if (idCompany != null && authenticationError == false) { if (dtoResultUserAuthentication.User.IdCompany != idCompany) { authenticationError = true; dtoResultUserAuthentication.MessageAuthentication = "AccessDenied"; } } if (idApplication != null && authenticationError == false) { CompanyApplicationDto dtoApplication = new CompanyApplicationDto(); dtoApplication.IdApplication = idApplication; dtoApplication.IdCompany = dtoResultUserAuthentication.User.IdCompany; List <CompanyApplicationDto> listApplicationDto = CompanyApplicationRepository.GetCompanyApplication(dtoApplication); if (listApplicationDto.Count != 1) { authenticationError = true; dtoResultUserAuthentication.MessageAuthentication = "AccessDenied";// - ApplicationNotFound"; } } } } if (authenticationError == false) { dtoResultUserAuthentication.AuthenticationCod = Convert.ToInt16(AuthenticationCode.Success); dtoResultUserAuthentication.MessageAuthentication = "Success"; } return(dtoResultUserAuthentication); }
public List <ResultNotificationsDto> SummaryNotifications(long idApplication, string username, int?specificGroup, long?idNotificationType, bool summaryView, bool onlyMainNotification) { long?idUser = null; List <ResultNotificationsDto> listNotificationsDto = new List <ResultNotificationsDto>(); List <AssociateUsersGroupDto> listgroup = new List <AssociateUsersGroupDto>(); if (!string.IsNullOrEmpty(username)) { List <UserApplicationDto> listUser = UserApplicationRepository.GetUserApplication(new UserApplicationDto() { UserName = username }); if (listUser.Count() == 0) { return(new List <ResultNotificationsDto>()); } else { idUser = listUser.First().IdUserApplication.Value; listgroup = AssociateUsersGroupRepository.GetAssociateUsersGroup(new AssociateUsersGroupDto() { IdUserApplication = idUser, IdUserGroup = specificGroup }); } } List <NotificationsSettingsDto> listConfigNoti = new List <NotificationsSettingsDto>(); //IdUserGroup = 0 All User Group listConfigNoti.Add(new NotificationsSettingsDto() { IdApplication = idApplication, IdUserGroup = 0, Active = true }); if (idUser != null) { listConfigNoti.Add(new NotificationsSettingsDto() { IdApplication = idApplication, IdUserApplication = idUser, Active = true }); } listgroup.ForEach(data => { listConfigNoti.Add(new NotificationsSettingsDto() { IdApplication = idApplication, IdUserGroup = data.IdUserGroup, Active = true }); }); listConfigNoti = NotificationsSettingsRepository.GetUpdateNotifications(listConfigNoti, summaryView); if (onlyMainNotification == true) { idNotificationType = (long)EnumReferenceTable.MainNotifications; } List <NotificationsDto> listNoti = new List <NotificationsDto>(); listConfigNoti.Select(data => data.IdNotification).Distinct().ToList().ForEach(data => { listNoti.Add(new NotificationsDto() { IdNotification = data, IdNotificationType = idNotificationType }); }); if (listNoti.Count > 0) { listNotificationsDto = NotificationsRepository.GetNotifications(listNoti).Select(Mapper.Map <NotificationsDto, ResultNotificationsDto>).ToList(); } if (onlyMainNotification != true) { listNotificationsDto.RemoveAll(filter => filter.IdNotificationType == (long)EnumReferenceTable.MainNotifications); } return(listNotificationsDto); }