public ActionResult Create([Bind(Include = "Id,City,Street,Phone,PersonID")] Address address) { if (ModelState.IsValid) { db.Addresses.Add(address); db.SaveChanges(); string url = Url.Action("Index", "Addresses", new { id = address.PersonID }); return(Json(new { success = true, url = url })); } return(PartialView("_Create", address)); }
public static bool Guardar(Entidades.Materias nueva) { bool retorno = false; using (var db = new DataDb()) { try { if (Buscar(nueva.MateriaId) == null) { db.MateriaDb.Add(nueva); db.SaveChanges(); retorno = true; } else { db.Entry(nueva).State = EntityState.Unchanged; retorno = true; } } catch (Exception) { throw; } } return(retorno); }
public static bool Guardar(Entidades.Estudiantes n) { bool retono = false; using (var db = new DataDb()) { try { foreach (var g in n.MateriaList) { db.Entry(g).State = System.Data.Entity.EntityState.Unchanged; } if (Buscar(n.EstudianteId) == null) { db.EstudiantesDb.Add(n); db.SaveChanges(); retono = true; } else { db.Entry(n).State = System.Data.Entity.EntityState.Unchanged; retono = true; } } catch (Exception) { throw; } } return(retono); }
public ActionResult Create(Racun Racuni) { try { if (ModelState.IsValid) { Racun racun = PripremiNoviRacun(Racuni); _db.Racuni.Add(racun); _db.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(StavkaRacuna stavka) { try { if (ModelState.IsValid) { stavka.ListaProizvoda = PripremiListuProizvoda(); if (_db.StavkeRacuna.Where(x => x.ProizvodId == stavka.ProizvodId).FirstOrDefault() == null) { _db.StavkeRacuna.Add(stavka); } else { _db.StavkeRacuna.Where(x => x.ProizvodId == stavka.ProizvodId).FirstOrDefault().Kolicina += stavka.Kolicina; } _db.SaveChanges(); _db.Racuni.Find(stavka.RacunId).Ukupno = VrednostRacuna(stavka.RacunId); _db.SaveChanges(); } return(RedirectToAction("Index", new { racunId = stavka.RacunId })); } catch { return(View()); } }
private void TransferToDatabase() { DataDb db = _serviceProvider.CreateScope().ServiceProvider.GetService <DataDb>(); List <DataEntry> entriesGrouped = DataEntries .GroupBy(e => new { e.ClientId, Time = e.Time.Round(TimeSpan.FromSeconds(1)) }) .Select(grouping => { return(new DataEntry() { Time = grouping.Key.Time, ClientId = grouping.Key.ClientId, AverageDiff = grouping.Average(v => v.AverageDiff) }); }) .ToList(); db.Entries.AddRange(entriesGrouped); db.SaveChanges(); DataEntries.Clear(); _logger.LogInformation($"Storing data to database"); }