public bool UpdateOutlet(int id, Data.Entities.Outlet1 outlet) { try { var existingOutlet = _applicationdbcontext.Outlets.FirstOrDefault(p => p.OutletId == id); if (outlet != null) { existingOutlet.OutletName = outlet.OutletName; existingOutlet.StreetName = outlet.StreetName; existingOutlet.Landmark = outlet.Landmark; existingOutlet.NoOfPackets = outlet.NoOfPackets; existingOutlet.NoOfVolunteers = outlet.NoOfVolunteers; existingOutlet.FoodType = outlet.FoodType; existingOutlet.Date = outlet.Date; _applicationdbcontext.Outlets.Update(existingOutlet); _applicationdbcontext.SaveChanges(); } return(true); } catch (Exception) { throw; } }
public bool AddOutlet(Data.Entities.Outlet1 outletin) { try { var outletsPerDayServingBothFood = _applicationdbcontext.Outlets.Where(x => x.Date == outletin.Date).Where(x => x.FoodType == "Both"); var outletsServingBothFoodCount = outletsPerDayServingBothFood.Count(); var outletsPerDay = _applicationdbcontext.Outlets.Where(p => p.Date == outletin.Date); var outletsPerDayCount = outletsPerDay.Count(); if (outletsPerDayCount < 10 && outletsServingBothFoodCount < 3) { _applicationdbcontext.Outlets.Add(new Outlet1() { OutletId = outletin.OutletId, OutletName = outletin.OutletName, StreetName = outletin.StreetName, Landmark = outletin.Landmark, NoOfPackets = outletin.NoOfPackets, NoOfVolunteers = outletin.NoOfVolunteers, FoodType = outletin.FoodType, Date = outletin.Date, }); _applicationdbcontext.SaveChanges(); return(true); } else { return(false); } } catch (Exception) { throw; } }