private static List <Holiday> GetHolidaysFromRules(INotificationHandler notificationHandler, List <RuleHoliday> rulesHolidays, int start, int end, int year, IUserLogged userLogged) { List <Holiday> holidays = null; if (rulesHolidays != null && rulesHolidays.Count() > 0) { holidays = new List <Holiday>(); try { Guid userId = userLogged.GetUserId(); RuleHoliday ruleHoliday = null; DateTime? holidayDate = null; for (int i = start, j = end; i < j; i++) { ruleHoliday = rulesHolidays[i]; holidayDate = null; if (ruleHoliday.BussinessRule.HasValue()) { if (!ApplyBusinessRuleForDate(notificationHandler, ruleHoliday, year, out holidayDate)) { ApplyBusinessRuleForTime(notificationHandler, ruleHoliday, year, out holidayDate); } } else { if (ruleHoliday.Month.HasValue && ruleHoliday.Day.HasValue) { holidayDate = new DateTime(year, ruleHoliday.Month.Value, ruleHoliday.Day.Value); } } if (holidayDate == null) { var notification = new DomainNotification(ruleHoliday.Id.ToString(), $"O feriado {ruleHoliday.NativeHolidayName} do {ruleHoliday.CountryIsoCode} não tem data."); notificationHandler.NotifyError(notification); } else { var holiday = Holiday.CreateHoliday(null, EntityStatus.Active, ActionType.Register, userId, ruleHoliday.CountryId, ruleHoliday.StateId, holidayDate.Value, ruleHoliday.HolidayType, ruleHoliday.Optional, ruleHoliday.NativeHolidayName, ruleHoliday.EnglishHolidayName, ruleHoliday.CountryIsoCode, ruleHoliday.StateIsoCode, ruleHoliday.CityName, ruleHoliday.CityCode); holidays.Add(holiday); } } } catch (Exception ex) { throw ex; } } return(holidays); }
private static List <Country> GetCountriesFromCsv(string[,] countriesCsv, int start, int end, IUserLogged userLogged) { List <Country> countries = null; if (countriesCsv != null && countriesCsv.GetLength(0) > 0) { countries = new List <Country>(); try { Guid userId = userLogged.GetUserId(); for (int i = start, j = end; i < j; i++) { string numericCode = countriesCsv[i, 1].Trim(); string alphaIsoCode2 = countriesCsv[i, 2].Trim(); string alphaIsoCode3 = countriesCsv[i, 3].Trim(); string name = countriesCsv[i, 4].Trim(); string shortName = countriesCsv[i, 5].Trim(); string languageCode = countriesCsv[i, 6].Trim(); string regionName = countriesCsv[i, 7].Trim(); string subRegionName = countriesCsv[i, 8].Trim(); string intermediateRegionName = countriesCsv[i, 9].Trim(); int regionCode = countriesCsv[i, 10].HasValue() ? int.Parse(countriesCsv[i, 10].Trim()) : 0; int subRegionCode = countriesCsv[i, 11].HasValue() ? int.Parse(countriesCsv[i, 11].Trim()) : 0; int intermediateRegionCode = countriesCsv[i, 12].HasValue() ? int.Parse(countriesCsv[i, 12].Trim()) : 0; string pathCountryImage = null; var country = Country.CreateCountry(null, EntityStatus.Active, ActionType.Register, userId, numericCode, alphaIsoCode2, alphaIsoCode3, name, shortName, languageCode, regionName, subRegionName, intermediateRegionName, regionCode, subRegionCode, intermediateRegionCode, pathCountryImage); countries.Add(country); } } catch (Exception ex) { throw ex; } } return(countries); }
private static async Task <List <State> > GetStatesFromCsvAsync(string[,] statesCsv, int start, int end, ICountryRepository countryRepository, IUserLogged userLogged) { List <State> states = null; if (statesCsv != null && statesCsv.GetLength(0) > 0) { states = new List <State>(); try { Guid userId = userLogged.GetUserId(); Guid countryId = Guid.Empty; Country country = null; for (int i = start, j = end; i < j; i++) { string countryIsoCode = statesCsv[i, 1].Trim(); string stateIsoCode = statesCsv[i, 2].Trim(); string name = statesCsv[i, 3].Trim(); string pathStateImage = null; if (country == null || country.CountryIsoCode3 != countryIsoCode) { country = (await countryRepository.FindAsync(c => c.CountryIsoCode3 == countryIsoCode)).FirstOrDefault(); countryId = country != null ? country.Id : Guid.Empty; } var state = State.CreateState(null, EntityStatus.Active, ActionType.Register, userId, countryId, countryIsoCode, stateIsoCode, name, pathStateImage); states.Add(state); } } catch (Exception ex) { throw ex; } } return(states); }
public async Task <ListPostResponse> ListPosts() { Guid responsableId = await userLogged.GetUserId(); return(await this.postService.ListPosts(responsableId)); }
private static async Task <List <RuleHoliday> > GetRulesHolidaysFromCsvAsync(string[,] rulesHolidaysCsv, int start, int end, ICountryRepository countryRepository, IStateRepository stateRepository, IUserLogged userLogged) { List <RuleHoliday> rules = null; if (rulesHolidaysCsv != null && rulesHolidaysCsv.GetLength(0) > 0) { rules = new List <RuleHoliday>(); try { Guid userId = userLogged.GetUserId(); Guid countryId = Guid.Empty; Guid? stateId = null; Country country = null; string stateCodePrevious = "?"; for (int i = start, j = end; i < j; i++) { var id = rulesHolidaysCsv[i, 0].HasValue() ? int.Parse((rulesHolidaysCsv[i, 0]).Trim()) : -1; var countryCode = rulesHolidaysCsv[i, 1].Trim(); var stateName = rulesHolidaysCsv[i, 2].Trim(); var stateCode = rulesHolidaysCsv[i, 3].Trim(); var month = rulesHolidaysCsv[i, 4].ToMonth(); var day = rulesHolidaysCsv[i, 5].ToDay(); var nativeDescription = rulesHolidaysCsv[i, 6].Trim(); var alternativeDescription = rulesHolidaysCsv[i, 7].Trim(); var holidayType = rulesHolidaysCsv[i, 8].Replace(" ", " ").Trim(); var cityName = rulesHolidaysCsv[i, 9].Trim(); var cityCode = rulesHolidaysCsv[i, 10].Trim(); var optional = rulesHolidaysCsv[i, 11].HasValue(); var bussinessRule = rulesHolidaysCsv[i, 12].ToLower().Trim().Replace(" ", ""); var comments = rulesHolidaysCsv[i, 13].Trim(); if (country == null || country.CountryIsoCode3 != countryCode) { country = (await countryRepository.FindAsync(c => c.CountryIsoCode3 == countryCode)).FirstOrDefault(); countryId = country != null ? country.Id : Guid.Empty; } if (stateCode.HasValue() && stateCode != stateCodePrevious) { stateCodePrevious = stateCode; stateId = await SetStateIdAsync(stateRepository, stateCode, countryCode); } HolidayType type = SetHolidayType(holidayType, cityName, stateCode); comments = SetComments(holidayType, comments); var ruleHoliday = RuleHoliday.CreateRuleHoliday(null, EntityStatus.Active, ActionType.Register, userId, countryId, stateId, countryCode, stateCode, cityCode, cityName, type, nativeDescription, alternativeDescription, month, day, optional, bussinessRule, comments); rules.Add(ruleHoliday); } } catch (Exception ex) { throw ex; } } return(rules); }