public override OrderOut Add(OrderOut aEntity) { OrderOut terug = null; using (KfsContext ctx = new KfsContext(_constring)) { //bijwerken stok foreach (var lines in aEntity.OrderLineOuts) { Product gevondenProdukt = ctx.Products.FirstOrDefault(x => x.EAN == lines.EAN_Product); if (gevondenProdukt == null) { throw new KeyNotFoundException($"EAN {lines.EAN_Product}, niet gevonden bij het bijwerken van de stock"); } gevondenProdukt.CountInStock -= lines.NumberOfProducts; } //als dat gelukt is dan bijwerken OrderOut terug = base.Add(aEntity); //uiteindelijk saven ctx.SaveChanges(); } return(terug); }
public Employee Update(Employee aEmployee) { Employee gevonden = null; using (KfsContext ctx = new KfsContext(_constring)) { gevonden = ctx.Set <Employee>() .FirstOrDefault(u => u.Id == aEmployee.Id); if (gevonden == null) { throw new DuplicateNameException($"user with {aEmployee.FirstName} not exist"); } ctx.Entry(gevonden).CurrentValues.SetValues(aEmployee); ctx.Entry(gevonden.EmpAddress).CurrentValues.SetValues(aEmployee.EmpAddress); ctx.Entry(gevonden.EmpContract).CurrentValues.SetValues(aEmployee.EmpContract); ctx.Entry(gevonden.EmpAppAccount).CurrentValues.SetValues(aEmployee.EmpAppAccount); ctx.SaveChanges(); } return(gevonden); }
public void HandlelOrders(List <int> aListOrder, int aEmployeeId) { DateTime nu = DateTime.Now; using (KfsContext ctx = new KfsContext(_constring)) { foreach (var item in aListOrder) { OrderIn gevondenOrderIn = ctx.OrderIns .Include(nameof(OrderIn.OrderLineIns)) .Include(nameof(OrderIn.OrderLineIns) + "." + nameof(OrderLineIn.Product)) .Where(x => x.Id == item).FirstOrDefault(); if (gevondenOrderIn == null) { throw new KeyNotFoundException($"id {item} niet gevonden tijdens het afhandelen van OrderIn"); } foreach (var orderline in gevondenOrderIn.OrderLineIns) { //de stock updaten orderline.Product.CountInStock += orderline.NumberOfProducts; } gevondenOrderIn.Id_HandledBy = aEmployeeId; gevondenOrderIn.HandledAt = nu; } ctx.SaveChanges(); } }
public Client Update(Client aClient) { Client gevonden = null; using (KfsContext ctx = new KfsContext(_constring)) { gevonden = ctx.Set <Client>() .FirstOrDefault(u => u.Id == aClient.Id); if (gevonden == null) { throw new DuplicateNameException($"user with {aClient.FirstName} not exist"); } ctx.Entry(gevonden).CurrentValues.SetValues(aClient); ctx.Entry(gevonden.CltAddresss.ToList()[0]).CurrentValues.SetValues(aClient.CltAddresss.ToList()[0]); ctx.SaveChanges(); } return(gevonden); }
//{ // return _context.Set<TDSentity>().ToList(); //} ////---------------------------------------------------------------------------------- //public virtual IEnumerable<TDSentity> Find(Expression<Func<TDSentity, bool>> aPredicate) //{ // throw new NotImplementedException(); //} ////---------------------------------------------------------------------------------- //public virtual TDSentity SingleOrDefault(Expression<Func<TDSentity, bool>> aPredicate) //{ // return _context.Set<TDSentity>().SingleOrDefault(aPredicate); //} ////===================================================================================== Create's public virtual TDSentity Add(TDSentity aEntity) { if (aEntity is IDateTimeCreateAndUpdate) { DateTime nu = DateTime.Now; (aEntity as IDateTimeCreateAndUpdate).CreatedAt = nu; (aEntity as IDateTimeCreateAndUpdate).UpdatedAt = nu; } using (KfsContext ctx = new KfsContext(_constring)) { try { ctx.Set <TDSentity>().Add(aEntity); ctx.SaveChanges(); } //catch (System.Data.Entity.Infrastructure.DbUpdateException uex) //{ // if(uex.InnerException.InnerException.HResult == -2146232060) // { // throw new EvaluateException("bestaat"); // } //} catch (System.Data.Entity.Validation.DbEntityValidationException ex) { throw new EvaluateException("FATAL ERROR: fout tijdens het wegschrijven naar DB\n" + $"{ex.EntityValidationErrors.ToList()[0].ValidationErrors.ToList()[0].ErrorMessage}"); //System.Windows.Forms.MessageBox.Show(ex.EntityValidationErrors.ToList()[0].ValidationErrors.ToList()[0].ErrorMessage); } } return(aEntity); }
public Product Update(Product aProduct) { Product gevonden = null; using (KfsContext ctx = new KfsContext(_constring)) { gevonden = ctx.Set <Product>() .FirstOrDefault(u => u.EAN == aProduct.EAN); if (gevonden == null) { throw new DuplicateNameException($"user with {aProduct.EAN} not exist"); } ctx.Entry(gevonden).CurrentValues.SetValues(aProduct); //ctx.Entry(gevonden.EmpAddress).CurrentValues.SetValues(aEmployee.EmpAddress); //ctx.Entry(gevonden.EmpContract).CurrentValues.SetValues(aEmployee.EmpContract); //ctx.Entry(gevonden.EmpAppAccount).CurrentValues.SetValues(aEmployee.EmpAppAccount); ctx.SaveChanges(); } return(gevonden); }
public Employee Delete(Employee aEmployee) { Employee gevonden = null; using (KfsContext ctx = new KfsContext(_constring)) { gevonden = ctx.Set <Employee>() .FirstOrDefault(u => u.Id == aEmployee.Id); if (gevonden == null) { throw new DuplicateNameException($"user with {aEmployee.EmpAppAccount.UserName} not exist"); } gevonden.IsActive = false; ctx.SaveChanges(); } return(gevonden); }
public Client Delete(Client aClient) { Client gevonden = null; using (KfsContext ctx = new KfsContext(_constring)) { gevonden = ctx.Set <Client>() .FirstOrDefault(u => u.Id == aClient.Id); if (gevonden == null) { throw new DuplicateNameException($"user with {aClient.FirstName} not exist"); } gevonden.IsActive = false; ctx.SaveChanges(); } return(gevonden); }