public static void RemoveOrganization(Common.Organization organization) { Organization e = Mapper.CastOrganization(organization); using (dbRamotEntities db = new dbRamotEntities()) { db.Organization.Remove(e); db.SaveChanges(); } }
internal static Organization CastOrganization(Common.Organization organization) { return(organization == null ? null : new Organization() { Id = organization.Id, Name = organization.Name, Address = organization.Address, email = organization.email, Comments = organization.Comments, Contact = organization.Contact, Phone = organization.Phone }); }
public static int AddOrganization(Common.Organization organization, Category[] categories) { int x = 0; Organization e = Mapper.CastOrganization(organization); using (dbRamotEntities db = new dbRamotEntities()) { foreach (var item in categories) { var c = db.Categories.FirstOrDefault(ca => ca.Id == item.Id); e.Categories.Add(c); } db.Organization.Add(e); db.SaveChanges(); x = db.Organization.Local[0].Id; } return(x); }
public static int UpdateOrganization(Common.Organization organization, Category[] categories) { int x = 0; Organization e = Mapper.CastOrganization(organization); using (dbRamotEntities db = new dbRamotEntities()) { db.Organization.Find(organization.Id).Categories.Clear(); foreach (var item in categories) { var c = db.Categories.FirstOrDefault(ca => ca.Id == item.Id); db.Organization.Find(organization.Id).Categories.Add(c); } db.Entry <Organization>(db.Set <Organization>().Find(e.Id)).CurrentValues.SetValues(e); db.SaveChanges(); x = db.Organization.Local[0].Id; } return(x); }