protected void OnPropertyChanged(string prop) { if (prop == "Id") { HoursWeekly = Fun.GetCleanerHours(Id, DateTime.Now); } if (PropertyChanged != null) { try { using (var db = new PodaciContext()) { db.Update(this); db.SaveChanges(); } } catch (Exception ex) { MessageBox.Show("Cleaner Update Error: " + ex.Message); } PropertyChanged(this, new PropertyChangedEventArgs(prop)); } }
private void setLocations(int _id) { try { if (Client != null) { Locations = new Dictionary <int, string> { { 0, Client.Address }, { 1, Client.Address2 }, { 2, Client.Address3 }, { 3, Client.Address4 } } } ; else if (_id != 0) { using (var db = new PodaciContext()) { if (db.Clients.Any()) { var c = db.Clients.FirstOrDefault(x => x.Id == _id); Locations = new Dictionary <int, string> { { 0, c.Address }, { 1, c.Address2 }, { 2, c.Address3 }, { 3, c.Address4 } }; } } } } catch (Exception ex) { MessageBox.Show("setLocations Error: " + ex.Message); } }
protected void OnPropertyChanged(string prop) { if (PropertyChanged != null) { try { using (var db = new PodaciContext()) { db.Update(this); db.SaveChanges(); } } catch (Exception ex) { MessageBox.Show("Team Update Error: " + ex.Message); } PropertyChanged(this, new PropertyChangedEventArgs(prop)); } }
public void ConvertAmount() { try { double amount = 0; if (TimeEnd != null && TimeStart != null && ServiceId != null && ServiceId != 0) { var hours = ConvertTime(); using (var db = new PodaciContext()) { var rate = db.Services.FirstOrDefault(x => x.Id == ServiceId)?.Rate; if (rate != null) { amount = (double)rate * hours; } var serviceJobs = db.CleaningJobs.Include(x => x.ServiceJobs).ThenInclude(y => y.Service).FirstOrDefault(x => x.Id == Id).ServiceJobs; if (serviceJobs != null && serviceJobs.Count > 0) { foreach (var serviceJob in serviceJobs) { if (serviceJob.Service?.Rate != null) { amount += (double)serviceJob.Service.Rate * hours; } } } } } Amount = (decimal)amount; } catch (Exception ex) { MessageBox.Show("ConvertAmount Error: " + ex.Message); } }
protected void OnPropertyChanged(string prop) { if (prop == "Date" && Date != null) { Week = Fun.getWeek(Date); Day = Fun.getDay(Date); } if (prop == "ClientId") { setLocations(_ClientId); } if (PropertyChanged != null) { if (prop == "Date" && Date != null) { RepeatJob = null; RepeatJobId = null; } else if (prop != "Locations") { if (RepeatJobId != null && RepeatJob != null) { if (!changed) { changed = true; } } } if (prop == "TimeStart" && TimeStart != null) { if (TimeEnd != null) { NoOfHours = ConvertTime(); } } else if (prop == "TimeEnd" && TimeEnd != null) { if (TimeStart != null) { NoOfHours = ConvertTime(); } } if (prop == "TeamId" && TeamId != null) { CleanerId = null; Cleaner = null; } else if (prop == "CleanerId" && CleanerId != null) { TeamId = null; Team = null; } if (CleanerId == 0) { CleanerId = null; Cleaner = null; } if (TeamId == 0) { TeamId = null; Team = null; } if (ServiceId == 0) { ServiceId = null; Service = null; } if (prop == "TimeEnd" || prop == "TimeStart" || prop == "ServiceId") { ConvertAmount(); } try { using (var db = new PodaciContext()) { db.Update(this); db.SaveChanges(); } } catch (Exception ex) { MessageBox.Show("CleaningJob Update Error: " + ex.Message); } PropertyChanged(this, new PropertyChangedEventArgs(prop)); } }