public int Save(TenantModel model) { try { using (var context = new RentalTrackerEntities()) { DAL.Context.Tenant entity; if (model.Id <= 0) { entity = context.Tenants.Create(); context.Tenants.Add(entity); } else { entity = context.Tenants.Single(x => x.Id == model.Id); } entity.PropertyId = model.PropertyId; entity.Name = model.Name; entity.StartDate = model.StartDate; entity.EndDate = model.EndDate; entity.RentalPrice = model.RentalPrice; return(context.SaveChanges()); } } catch (Exception ex) { //log ex throw; } }
public void Delete(int id) { try { using (var context = new RentalTrackerEntities()) { var t = context.Tenants.Single(x => x.Id == id); context.Tenants.Remove(t); context.SaveChanges(); } } catch (Exception) { //log ex throw; } }
public void Delete(int id) { try { using (var context = new RentalTrackerEntities()) { foreach (var t in context.Tenants.Where(x => x.PropertyId == id)) { context.Tenants.Remove(t); } var p = context.Properties.Single(x => x.Id == id); context.Properties.Remove(p); context.SaveChanges(); } } catch (Exception) { //log ex throw; } }
public int Save(PropertyModel model) { try { using (var context = new RentalTrackerEntities()) { DAL.Context.Property entity; if (model.Id <= 0) { entity = context.Properties.Create(); entity.Created = DateTime.Now; context.Properties.Add(entity); } else { entity = context.Properties.Single(x => x.Id == model.Id); } entity.PropertyName = model.PropertyName; entity.Address = model.Address; entity.Address2 = model.Address2; entity.City = model.City; entity.State = model.State; entity.ZipCode = model.ZipCode; entity.OwnerName = model.OwnerName; return(context.SaveChanges()); } } catch (Exception ex) { //log ex throw; } }