public static void UpdateVolunteerAndFamily(Common.VolunteerAndFamily vaf) { VolunteerAndFamily g = Mapper.CastVolunteerAndFamily(vaf); using (dbRamotEntities db = new dbRamotEntities()) { db.Entry <VolunteerAndFamily>(db.Set <VolunteerAndFamily>().Find(g.Id)).CurrentValues.SetValues(g); db.SaveChanges(); } }
internal static Common.VolunteerAndFamily CastVolunteerAndFamilyToComon(VolunteerAndFamily vaf) { return(vaf == null ? null : new Common.VolunteerAndFamily() { Id = vaf.Id, Category = Mapper.CastCategoryToCommon(vaf.Categories), Family = Mapper.CastFamilyToComon(vaf.Families), Volunteer = Mapper.CastVolunteerToComon(vaf.Volunteers), Comments = vaf.Comments, DateAdded = vaf.dateAdded }); }
public static void AddVolunteerAndFamily(Common.VolunteerAndFamily vaf) { VolunteerAndFamily g = Mapper.CastVolunteerAndFamily(vaf); using (dbRamotEntities db = new dbRamotEntities()) { //if (db.VolunteerAndFamily.Contains(g)) Categories c = null; if (vaf.Category != null) { c = db.Categories.FirstOrDefault(ca => ca.Id == vaf.Category.Id); } var v = db.Volunteers.FirstOrDefault(ca => ca.Id == vaf.Volunteer.Id); var f = db.Families.FirstOrDefault(ca => ca.Id == vaf.Family.Id); g.Categories = c; g.Volunteers = v; g.Families = f; db.VolunteerAndFamily.Add(g); db.SaveChanges(); } }