public void Edit(long meterId, Meter.Fields fieldToEdit, string value) { Meter met = GetMeter(meterId); switch (fieldToEdit) { case Meter.Fields.Name: if (met.Name != value) { met.Name = value; } break; case Meter.Fields.Discription: if (met.Discription != value) { met.Discription = value; } break; case Meter.Fields.SumReadings: { if (double.TryParse(value, out double doubleVal) && met.SumReadings != doubleVal) { met.SumReadings = doubleVal; } } break; case Meter.Fields.Capacity: { if (double.TryParse(value, out double doubleVal) && met.Capacity != doubleVal) { met.Capacity = doubleVal; } } break; case Meter.Fields.ProductionDate: if (DateTime.TryParse(value, out DateTime dtValue) && met.ProductionDate != dtValue) { met.ProductionDate = dtValue; } break; default: throw new NotImplementedException(); } cont.SaveChanges(); }
public void DeleteUser(string login) { User us = GetUser(login); { MeterRepository metRepo = new MeterRepository(cont); foreach (Meter met in us.Meters) { metRepo.DeleteMeter(met.ProductionId); } } cont.UserSet.Remove(us); cont.SaveChanges(); }
public void DeletePage(int id) { ModelContainer1 mc = new ModelContainer1(); var page = (from x in mc.PageSet where x.Id == id select x).First(); mc.PageSet.DeleteObject(page); mc.SaveChanges(); }
public void UpdatePage(int id, string name) { ModelContainer1 mc = new ModelContainer1(); var page = (from x in mc.PageSet where x.Id == id select x).First(); page.Name = name; mc.SaveChanges(); }
public void SaveContent(string html, int id) { ModelContainer1 mc = new ModelContainer1(); var page = (from x in mc.PageSet where x.Id == id select x).First(); page.Content = html; mc.SaveChanges(); }
public void UpdateLogo(string html) { ModelContainer1 mc = new ModelContainer1(); var page = (from x in mc.AllPagesSet select x).First(); page.Logo = html; mc.SaveChanges(); }
public bool Delete(T entity) { using (ModelContainer1 context = new ModelContainer1()) { context.Entry(entity).State = EntityState.Deleted; return(context.SaveChanges() > 0); } }
public bool Create(T entity) { using (ModelContainer1 context = new ModelContainer1()) { context.Set <T>().Add(entity); return(context.SaveChanges() > 0); } }
public bool CreateCliente(Cliente cliente) { using (ModelContainer1 context = new ModelContainer1()) { context.ClienteSet.Add(cliente); cliente.Rol.ToList().ForEach(u => context.Entry(u).State = EntityState.Unchanged); return(context.SaveChanges() > 0); } }
public void Delete(Expression <Func <T, bool> > predicate) { using (ModelContainer1 context = new ModelContainer1()) { var entities = context.Set <T>().Where(predicate).ToList(); entities.ForEach(x => context.Entry(x).State = EntityState.Deleted); context.SaveChanges(); } }
public bool CreatePedidoWithProducts(Pedido pedido) { using (ModelContainer1 container1 = new ModelContainer1()) { container1.PedidoSet.Add(pedido); pedido.Producto.ToList().ForEach(u => container1.Entry(u).State = EntityState.Unchanged); return(container1.SaveChanges() > 0); } }
public void CreatePage(string name) { ModelContainer1 mc = new ModelContainer1(); var newPage = new Page(); newPage.Name = name; newPage.Content = "<li class='editable'>Welcome to the new site!</li><li> </li>"; mc.AddToPageSet(newPage); mc.SaveChanges(); }
public void DeleteReading(long id) { Reading read = GetReading(id); read.Meter.Readings.Remove(read); cont.ReadingSet.Remove(read); cont.SaveChanges(); }
public void DeleteDocument(long id) { Document doc = GetDocument(id); doc.Meter.Documents.Remove(doc); cont.DocumentSet.Remove(doc); cont.SaveChanges(); }
public void AddMarker(int siteId, string markerX, string markerY, string comment) { ModelContainer1 mc = new ModelContainer1(); var page = (from x in mc.PageSet where x.Id == siteId select x).First(); page.Marker_x = markerX; page.Marker_y = markerY; page.Marker_comment = comment; mc.SaveChanges(); }
public void UpdateColor(int red, int green, int blue) { ModelContainer1 mc = new ModelContainer1(); var page = (from x in mc.AllPagesSet select x).First(); page.ColorR = red; page.ColorG = green; page.ColorB = blue; mc.SaveChanges(); }
public void DeleteMarker(int siteId) { ModelContainer1 mc = new ModelContainer1(); var page = (from x in mc.PageSet where x.Id == siteId select x).First(); page.Marker_x = null; page.Marker_y = null; page.Marker_comment = null; mc.SaveChanges(); }
public bool UpdateMultiplesStock(IDictionary <int, int> productosNewStock) { using (ModelContainer1 context = new ModelContainer1()) { foreach (var productoNewStock in productosNewStock) { Producto producto = context.ProductoSet.Single(u => u.Id == productoNewStock.Key); producto.Cantidad = producto.Cantidad - productoNewStock.Value; } return(context.SaveChanges() > 0); } }
public void DeleteParametr(int id) { Parametr par = GetParametr(id); foreach (Meter met in par.Meters) { met.Parametrs.Remove(par); } cont.ParametrSet.Remove(par); cont.SaveChanges(); }
public void EditMeter(long meterId, InstalledMeter.Fields fieldToEdit, string value) { InstalledMeter met = GetInstMeter(meterId); if (met == null) { return; } switch (fieldToEdit) { case InstalledMeter.Fields.ExpirationDate: if (DateTime.TryParse(value, out DateTime dtVal) && met.ExpirationDate != dtVal) { met.ExpirationDate = dtVal; } break; default: throw new NotImplementedException(); } cont.SaveChanges(); }