public virtual void Update(Collaborator collaborator) { using (var context = new SPSDb()) { var entity = context.Collaborators.SingleOrDefault(c => c.Email == collaborator.Email); if (entity == null) { return; } collaborator.Id = entity.Id; context.Entry(entity).CurrentValues.SetValues(collaborator); if (collaborator.Address != null) { var address = context.Addresses.SingleOrDefault(a => a.PostalCode == collaborator.Address.PostalCode); if (address == null) { address = collaborator.Address; } entity.Address = address; } if (collaborator.Parking != null) { entity.Parking = context.Parkings.SingleOrDefault(p => p.CNPJ == collaborator.Parking.CNPJ); } context.SaveChanges(); } }
public virtual void Update(Parking parking) { using (var context = new SPSDb()) { var entity = context.Parkings.Find(parking.CNPJ); if (entity == null) { return; } context.Entry(entity).CurrentValues.SetValues(parking); if (parking.Address != null) { var address = context.Addresses.SingleOrDefault(a => a.PostalCode == parking.Address.PostalCode); if (address == null) { address = parking.Address; } entity.Address = address; } if (parking.LocalManager != null) { entity.LocalManager = context.LocalManagers.SingleOrDefault(l => l.CPF == parking.LocalManager.CPF); } entity.Prices = parking.Prices; context.SaveChanges(); } }
public virtual void Add(Collaborator collaborator) { using (var context = new SPSDb()) { if (this.Find(collaborator.CPF) != null) { throw new UniqueKeyViolationException(string.Format("There is already a collaborator with CPF {0}.", collaborator.CPF)); } if (collaborator.Address != null) { var address = context.Addresses.SingleOrDefault(a => a.PostalCode == collaborator.Address.PostalCode); if (address != null) { collaborator.Address = address; } } if (collaborator.Parking != null) { collaborator.Parking = context.Parkings.SingleOrDefault(p => p.CNPJ == collaborator.Parking.CNPJ); } context.Collaborators.Add(collaborator); context.SaveChanges(); } }
public virtual IList <Address> FindAll() { using (var context = new SPSDb()) { return(context.Addresses.ToList()); } }
public void AttachToParking(Client client, string parkingCNPJ) { using (var context = new SPSDb()) { Client dbClient; Parking dbParking = context.Parkings.SingleOrDefault(p => p.CNPJ == parkingCNPJ); if (!string.IsNullOrEmpty(client.CPF)) { dbClient = context.Clients.Include(c => c.Parkings).SingleOrDefault(c => c.CPF == client.CPF); } else { dbClient = context.Clients.Include(c => c.Parkings).SingleOrDefault(c => c.Email == client.Email); } if (dbClient.Parkings.Count > 5) { throw new MaximumLimitReachedException("Número máximo de estacionamentos para esse cliente atingido"); } dbClient.Parkings.Add(dbParking); context.SaveChanges(); } }
public virtual void Update(LocalManager localManager) { using (var context = new SPSDb()) { var entity = context.LocalManagers.SingleOrDefault(l => l.Email == localManager.Email); if (entity == null) { return; } localManager.Id = entity.Id; context.Entry(entity).CurrentValues.SetValues(localManager); if (localManager.Address != null) { var address = context.Addresses.SingleOrDefault(a => a.PostalCode == localManager.Address.PostalCode); if (address == null) { address = localManager.Address; } entity.Address = address; } context.SaveChanges(); } }
public virtual void Update(Price price) { using (var context = new SPSDb()) { var entity = context.Prices.Find(price.Id); if (entity == null) { return; } if (price.IsDefault) { var oldDefault = context.Prices.SingleOrDefault(p => p.IsDefault); if (oldDefault != null) { oldDefault.IsDefault = false; } } price.Id = entity.Id; context.Entry(entity).CurrentValues.SetValues(price); if (price.Parking != null) { entity.Parking = context.Parkings.Find(entity.Parking.CNPJ); } context.SaveChanges(); } }
public void Update(UsageRecord usageRecord) { using (var context = new SPSDb()) { var entity = context.UsageRecords.Find(usageRecord.Id); if (entity == null) { return; } context.Entry(entity).CurrentValues.SetValues(usageRecord); if (usageRecord.Tag != null) { entity.Tag = context.Tags.Find(usageRecord.Tag.Id); } if (usageRecord.Plate != null) { entity.Plate = context.Plates.Find(usageRecord.Plate.Id); } if (usageRecord.Parking != null) { entity.Parking = context.Parkings.Find(usageRecord.Parking.CNPJ); } context.SaveChanges(); } }
public virtual void Add(Parking parking) { using (var context = new SPSDb()) { if (context.Parkings.Any(p => p.LocalManager.CPF == parking.LocalManager.CPF)) { throw new UniqueKeyViolationException("Esse admistrador já está associado a um estacionamento."); } if (parking.LocalManager != null) { parking.LocalManager = context.LocalManagers.SingleOrDefault(lm => lm.CPF == parking.LocalManager.CPF); } if (parking.Address != null) { var address = context.Addresses.SingleOrDefault(a => a.PostalCode == parking.Address.PostalCode); if (address != null) { parking.Address = address; } } context.Parkings.Add(parking); context.SaveChanges(); } }
public void Add(UsageRecord usageRecord) { using (var context = new SPSDb()) { if (usageRecord.Tag != null) { usageRecord.Tag = context.Tags.Find(usageRecord.Tag.Id); } if (usageRecord.Plate != null) { usageRecord.Plate = context.Plates.Find(usageRecord.Plate.Id); } if (usageRecord.Parking != null) { usageRecord.Parking = context.Parkings.Find(usageRecord.Parking.CNPJ); } if (usageRecord.Client != null) { usageRecord.Client = context.Clients.Find(usageRecord.Client.Id); } context.UsageRecords.Add(usageRecord); context.SaveChanges(); } }
public virtual void Remove(Collaborator collaborator) { using (var context = new SPSDb()) { context.Collaborators.Remove(collaborator); context.SaveChanges(); } }
public virtual void Remove(GlobalManager globalManager) { using (var context = new SPSDb()) { context.GlobalManagers.Remove(globalManager); context.SaveChanges(); } }
public virtual void Remove(Address address) { using (var context = new SPSDb()) { context.Addresses.Remove(address); context.SaveChanges(); } }
public virtual void Remove(Client client) { using (var context = new SPSDb()) { context.Clients.Remove(client); context.SaveChanges(); } }
public void Remove(UsageRecord usageRecord) { using (var context = new SPSDb()) { context.UsageRecords.Remove(usageRecord); context.SaveChanges(); } }
public virtual void Remove(Tag tag) { using (var context = new SPSDb()) { context.Tags.Remove(tag); context.SaveChanges(); } }
public virtual void Remove(Plate plate) { using (var context = new SPSDb()) { context.Plates.Remove(plate); context.SaveChanges(); } }
public virtual void Remove(Parking parking) { using (var context = new SPSDb()) { context.Parkings.Remove(parking); context.SaveChanges(); } }
public virtual void Remove(LocalManager localManager) { using (var context = new SPSDb()) { context.LocalManagers.Remove(localManager); context.SaveChanges(); } }
public virtual void Remove(Price price) { using (var context = new SPSDb()) { context.Prices.Remove(price); context.SaveChanges(); } }
public virtual IList <Price> FindAll() { using (var context = new SPSDb()) { return(context.Prices .Include("Parking") .ToList()); } }
public virtual Price Find(int id) { using (var context = new SPSDb()) { return(context.Prices .Include("Parking") .SingleOrDefault(p => p.Id == id)); } }
public virtual IList <LocalManager> FindAll() { using (var context = new SPSDb()) { return(context.LocalManagers .Include("Address") .ToList()); } }
public virtual IList <Tag> FindAll() { using (var context = new SPSDb()) { return(context.Tags .Include(t => t.Client.Parkings.Select(p => p.Clients.Select(c => c.Tags))) .ToList()); } }
public virtual Address Find(string cep) { Address address = null; using (var context = new SPSDb()) { address = context.Addresses.SingleOrDefault(a => a.PostalCode == cep); } return(address); }
public IList <UsageRecord> FindAll() { using (var context = new SPSDb()) { return(context.UsageRecords .Include("Tag") .Include("Plate") .Include("Parking") .Include("Client") .ToList()); } }
public virtual IList <Client> FindAll() { using (var context = new SPSDb()) { return(context.Clients .Include(c => c.Tags) .Include(c => c.Records) .Include(c => c.Parkings.Select(p => p.LocalManager)) .Include(c => c.Address) .ToList()); } }
public virtual GlobalManager Find(string cpf) { GlobalManager globalManager = null; using (var context = new SPSDb()) { globalManager = context.GlobalManagers .Include("Address") .SingleOrDefault(c => c.CPF == cpf); } return(globalManager); }
public virtual LocalManager Find(string cpf) { LocalManager localManager = null; using (var context = new SPSDb()) { localManager = context.LocalManagers .Include("Address") .SingleOrDefault(c => c.CPF == cpf); } return(localManager); }
public virtual Tag Find(string id) { Tag tag = null; using (var context = new SPSDb()) { tag = context.Tags .Include(t => t.Client.Parkings.Select(p => p.Clients.Select(c => c.Tags))) .SingleOrDefault(c => c.Id == id); } return(tag); }