public AddEditFoodSpec(Restaurant restaurant, FoodSpecialActions action, FoodSpecial spec = null) { InitializeComponent(); _spec = spec; _restaurantId = restaurant.Id; if (action == FoodSpecialActions.Add) { lblTitle.Text = "Add"; } else if (action == FoodSpecialActions.Edit) { lblTitle.Text = "Edit"; } #region Tap Events var tgr = new TapGestureRecognizer(); tgr.Tapped += async(s, e) => await Cancel(); lblCancel.GestureRecognizers.Add(tgr); tgr = new TapGestureRecognizer(); tgr.Tapped += async(s, e) => await AddUpdate(); lblSave.GestureRecognizers.Add(tgr); #endregion if (action == FoodSpecialActions.Edit) { SetEditFields(); } swAllDay.Toggled += ToggleVisibleTimes; }
public IHttpActionResult Post([FromBody] FoodSpecial foodSpecial) { //Get current users id foodSpecial.OwnerId = RequestContext.Principal.Identity.GetUserId(); lazyFoodSpecialsService.Value.Insert(foodSpecial); return(Ok()); }
/// <summary> /// Constructor /// </summary> /// <param name="spec">Food Special.</param> public ManageFoodSpecial(FoodSpecial spec) { InitializeComponent(); Title = spec.Title; _restaurant = spec.Restaurant; _spec = spec; NavigationPage.SetBackButtonTitle(this, ""); }
/// <summary> /// Sets the values of the readonly fields /// </summary> async Task SetFields() { var spec = await FoodSpecialService.GetSpecsFromStorageAsync(); _spec = spec.Single(x => x.SpecialId == _spec.SpecialId); RestaurantName.Text = _spec.Restaurant.Name; lblTitle.Text = _spec.Title; if (_spec.Description != null) { lblDescription.Text = _spec.Description; } else { lblDescription.Text = "(No description)"; lblDescription.TextColor = Color.Gray; } lblDays.Text = string.Join(", ", _spec.DaysOfWeek.Select(x => x.ToString())); //Comma deliminate days of week lblHours.Text = _spec.Hours; }
List <FoodSpecial> GetFlattenedFoodSpecials(IEnumerable <FoodSpecial> foodSpecials) { var foodSpecialsFlat = new List <FoodSpecial>(); //Flatten food specials so that there are multiple food specials created if food special occurs on multiple days. foreach (var spec in foodSpecials) { foreach (var dayOfWeek in spec.DaysOfWeek) { var newSpec = new FoodSpecial { SpecialId = spec.SpecialId, Title = spec.Title, StartTime = spec.StartTime, EndTime = spec.EndTime, AllDay = spec.AllDay, OwnerId = spec.OwnerId, RestaurantId = spec.RestaurantId }; #region Day of week case statement switch (dayOfWeek) { case DayOfWeek.Sunday: newSpec.Sunday = true; break; case DayOfWeek.Monday: newSpec.Monday = true; break; case DayOfWeek.Tuesday: newSpec.Tuesday = true; break; case DayOfWeek.Wednesday: newSpec.Wednesday = true; break; case DayOfWeek.Thursday: newSpec.Thursday = true; break; case DayOfWeek.Friday: newSpec.Friday = true; break; case DayOfWeek.Saturday: newSpec.Saturday = true; break; } #endregion foodSpecialsFlat.Add(newSpec); } } return(foodSpecialsFlat.ToList()); }
public void Update(FoodSpecial foodSpecial) { lazyFoodSpecialRepository.Value.Update(foodSpecial); }
public void Insert(FoodSpecial foodSpecial) { lazyFoodSpecialRepository.Value.Insert(foodSpecial); }
public IHttpActionResult Put([FromBody] FoodSpecial foodSpecial) { lazyFoodSpecialsService.Value.Update(foodSpecial); return(Ok()); }
/// <summary> /// Saves thes food spec to the database. /// </summary> async Task AddUpdate() { //Prevent double tap.. we'll see how this works if (tapped) { return; } tapped = true; //If validation fails, return if (ValidateForm() == false) { await DisplayAlert("Validation", errorMessage.ToString(), "OK"); tapped = false; return; } UserDialogs.Instance.ShowLoading("Saving", MaskType.Black); IFoodSpecialService _foodSpecService = Startup.Container.Get <IFoodSpecialService>(); #region Create new spec var newFoodSpec = new FoodSpecial { SpecialId = _spec != null ? _spec.SpecialId : 0, //new spec id is 0 Title = txtTitle.Text, Description = txtDescription.Text, Sunday = swSunday.IsToggled, Monday = swMonday.IsToggled, Tuesday = swTuesday.IsToggled, Wednesday = swWednesday.IsToggled, Thursday = swThursday.IsToggled, Friday = swFriday.IsToggled, Saturday = swSaturday.IsToggled, RestaurantId = _restaurantId }; #endregion //All day and set times are mutually exclusive if (swAllDay.IsToggled) { newFoodSpec.AllDay = true; } else { newFoodSpec.StartTime = tpStartTime.Time; newFoodSpec.EndTime = tpEndTime.Time; } try { await _foodSpecService.AddUpdate(newFoodSpec); UserDialogs.Instance.HideLoading(); await Navigation.PopModalAsync(true); tapped = false; } catch (Exception ex) { UserDialogs.Instance.HideLoading(); await DisplayAlert("Error", "Due to an error your food special has not been saved", "OK"); tapped = false; } }
public void Update(FoodSpecial entity) { throw new NotImplementedException(); }
public void Insert(FoodSpecial entity) { throw new NotImplementedException(); }