public Student DeleteStudent(Student student) { var res = _context.Student.FirstOrDefault(s => s.IndexNumber == student.IndexNumber); if (res == null) { return(null); } _context.Student.Remove(res); _context.SaveChanges(); return(res); }
public void PutOrder(int id, PutOrderRequest request) { if (!_context.Klient.Any(k => k.IdKlient == id)) { throw new ArgumentException($"Nie ma klienta z {id} w bazie"); } foreach (var wyrob in request.Wyroby) { var check = _context.WyrobCukierniczy.Any(w => w.Nazwa.Equals(wyrob.Wyrób)); if (!check) { throw new ArgumentException($"Nie ma takiego wyrobu jak {wyrob.Wyrób}"); } } int noweId = _context.Zamowienie.Max(z => z.IdZamowienia) + 1; _context.Zamowienie.Add(new Zamowienie { IdZamowienia = noweId, DataPrzyjecia = request.DataPrzyjecia, Uwagi = request.Uwagi, IdKlient = id }); foreach (var wyrob in request.Wyroby) { _context.ZamowienieWyrobCukierniczy.Add(new ZamowienieWyrobCukierniczy { IdWyrobuCukierniczego = _context.WyrobCukierniczy.Single(w => w.Nazwa.Equals(wyrob.Nazwa)).IdWyrobuCukierniczego, IdZamowienia = noweId, Ilosc = wyrob.Ilość, Uwagi = wyrob.Uwagi }); } _context.SaveChanges(); }