public GerenciarFeriadosViewModel (INavigation navigation, string gate_id = "", Holidays editHoliday = null)
		{
			gateId = gate_id;
			Holidays = App.Holidays;

			var notificator = DependencyService.Get<IToastNotificator> ();
			if (editHoliday != null) {
				holidayName = editHoliday.Name;
				holidayDate = new DateTime (Int32.Parse (editHoliday.Date.Substring (6, 4)),
					Int32.Parse (editHoliday.Date.Substring (3, 2)),
					Int32.Parse (editHoliday.Date.Substring (0, 2)));
				editHoliday.Recurrent = recursive;
			} else {
				holidayDate = DateTime.Today;
				recursive = true;
			}

			Navigation = navigation;

			messageVisibility = true;
			foreach (var hol in App.Holidays.Where(hol => hol.GateLicId.Equals(gateId)))
				messageVisibility = false;

			toolbarSaveCommand = new Command (async key => {
				var holiday = new Holidays (holidayName, gateId);

				if (editHoliday != null) {
					if (String.IsNullOrEmpty (holidayName)) {
						await notificator.Notify (ToastNotificationType.Error,
							"MySafety", "Nome é obrigatório", TimeSpan.FromSeconds (3));
						return;
					}
					if (App.Holidays.SkipWhile (skip => skip.Equals (editHoliday)).Any (hol => hol.Date.Equals (holidayDate))) {
						await notificator.Notify (ToastNotificationType.Error,
							"MySafety", "Já existe um feriado nesta data", TimeSpan.FromSeconds (3));
						return;
					}

					await new Repository<Holidays> ().UpdateAsync (editHoliday);

				} else {
					if (String.IsNullOrEmpty (holidayName)) {
						await notificator.Notify (ToastNotificationType.Error,
							"MySafety", "Nome é obrigatório", TimeSpan.FromSeconds (2));
						return;
					}

					if (App.Holidays.Contains (holiday)) {
						await notificator.Notify (ToastNotificationType.Error,
							"MySafety", "Já existe um feriado com esse nome", TimeSpan.FromSeconds (2));
						return;
					}

					int nextId = 0;
					int nextIdx;
					foreach (var hol in App.Holidays)
						if (hol.Equals (holidayDate)) {
							await notificator.Notify (ToastNotificationType.Error,
								"MySafety", "Já existe um feriado nesta data", TimeSpan.FromSeconds (3));
							return;
						} else {
							Int32.TryParse (hol.Id, out nextIdx);
							if (nextIdx > nextId)
								nextId = nextIdx;
						}

					holiday.Id = ++nextId + "";
					holiday.Date = string.Format ("{1:dd/MM/yyyy}", holidayDate);
					holiday.Recurrent = recursive;
					holiday.UserId = Settings.user_Id;

					App.Holidays.Add (holiday);
					messageVisibility = false;
					//await Navigation.PopModalAsync(true);
					holidayName = "";
					holidayDate = DateTime.Today;

					await DependencyService.Get<IToastNotificator> ()
                        .Notify (ToastNotificationType.Success, "MySafety", "Feriado adicionado", TimeSpan.FromSeconds (1));
					await App.tableFeriados.CreateAsync (holiday);
				}
			});

			toolbarAddHoliday = new Command (() => {
			});
		}
		async public Task Remove(Holidays holiday)
		{
			App.Holidays.Remove(holiday);
			await App.tableFeriados.RemoveAsync(holiday);
		}
		async public Task Remove (Holidays holiday)
		{
			await new Repository<Holidays> ().RemoveAsync (holiday);
			App.Holidays.Remove (holiday);
			messageVisibility = true;
			foreach (var hol in App.Holidays)
				if (hol.GateLicId.Equals (gateId))
					messageVisibility = false;
		}
Пример #4
0
 public bool Equals(Holidays other)
 {
     if (other == null)
         return false;
     return string.Equals (Name, other.Name, StringComparison.OrdinalIgnoreCase);
 }