public Entities.Crust Map(Domain.Models.Crust model, Entities.AnimalsDbContext context) { Entities.CRUST_TYPE crustType; switch (model) { case CheeseStuffedCrust: crustType = Entities.CRUST_TYPE.CheeseStuffed; break; case DeepDishCrust: crustType = Entities.CRUST_TYPE.DeepDish; break; case TraditionalCrust: crustType = Entities.CRUST_TYPE.Traditional; break; default: throw new ArgumentException("CrustMapper ran into an unknown type of crust when mapping from Domain Model to DB Model"); } var dbCrust = context.Crusts.FirstOrDefault(c => c.CrustType == crustType); if (dbCrust is not null) { return(dbCrust); } Entities.Crust crust = new Entities.Crust(); crust.CrustType = crustType; crust.Price = model.Price; return(crust); }
public Domain.Abstracts.ACrust Map(Entities.Crust model) { Domain.Abstracts.ACrust crust = null; switch (model.CrustType) { case CRUST_TYPE.CheeseStuffed: crust = new CheeseStuffedCrust(); break; case CRUST_TYPE.DeepDish: crust = new DeepDishCrust(); break; case CRUST_TYPE.Traditional: crust = new TraditionalCrust(); break; case CRUST_TYPE.Unknown: // TODO: add logging to these last 2 default: throw new ArgumentException("CrustMapper ran into an unknown Crust Type when mapping from DB Model to Domain Model"); } crust.Price = model.Price; crust.ID = model.ID; crust.Name = model.Name; crust.CrustType = model.CrustType; // not really needed return(crust); }
public Entities.Crust Map(Domain.Models.Crust model) { Entities.Crust crust = new Entities.Crust(); Entities.CRUST_TYPE crustType; switch (model) { case CheeseStuffedCrust: crustType = Entities.CRUST_TYPE.CheeseStuffed; break; case DeepDishCrust: crustType = Entities.CRUST_TYPE.DeepDish; break; case TraditionalCrust: crustType = Entities.CRUST_TYPE.Traditional; break; default: throw new ArgumentException("CrustMapper ran into an unknown type of crust when mapping from Domain Model to DB Model"); } crust.CrustType = crustType; crust.Price = model.Price; return(crust); }
public void Remove(Domain.Models.Crust t) { Entities.Crust dbCrust = mapper.Map(t); Entities.Crust crust = context.Crusts.ToList().Find(c => c.CrustType == dbCrust.CrustType); if (crust is not null) { context.Remove(crust); context.SaveChanges(); } }
public Domain.Abstracts.ACrust Update(Domain.Abstracts.ACrust updated) { // this will create a new crust entity // with the proper ID and attach it so it is being tracked // then it will change it's fields Entities.Crust mappedCrust = mapper.Map(updated, context, true); context.SaveChanges(); //context.ChangeTracker.Clear(); return(mapper.Map(mappedCrust)); }
public void Remove(int id) { Entities.Crust crust = context.Crusts.FirstOrDefault(c => c.ID == id); if (crust is not null) { context.Remove(crust); context.SaveChanges(); //context.ChangeTracker.Clear(); } }
public void Update(Domain.Models.Crust existing, Domain.Models.Crust updated) { Entities.Crust dbCrust = mapper.Map(existing); Entities.Crust crust = context.Crusts.ToList().Find(c => c.CrustType == dbCrust.CrustType); if (crust is not null) { Entities.Crust updatedMapped = mapper.Map(updated); crust.CrustType = updatedMapped.CrustType; crust.Price = updatedMapped.Price; context.SaveChanges(); } }
public Entities.Crust Map(Domain.Abstracts.ACrust model, Entities.PizzaBoxDbContext context, bool update = false) { Entities.Crust crust = context.Crusts.FirstOrDefault(crust => crust.ID == model.ID) ?? new Entities.Crust(); if (crust.ID != 0 && !update) { return(crust); } // either we are updating and we want to cascade all changes // or it didn't exist and we need to instantiate it crust.CrustType = model.CrustType; crust.Price = model.Price; crust.Name = model.Name; // if it is new, insert it into context so a future map can find it if (crust.ID == 0) { context.Crusts.Add(crust); } return(crust); }