/// <summary> /// Remove category from volunter /// </summary> /// <param name="id">Id of volunteer</param> /// <param name="category">Category object</param> public static void RemoveCategoryFromVolunteer(int id, Category category) { using (dbRamotEntities db = new dbRamotEntities()) { Volunteers v = db.Volunteers.Find(id); v.Categories.Remove(Mapper.CastCategory(category)); db.SaveChanges(); } }
/// <summary> /// Add category to volunter /// Helper func- does not work........ /// </summary> /// <param name="id">Id of volunteer</param> /// <param name="category">Category object</param> public static void AddCategoryToVolunteer(int id, Category[] category) { using (dbRamotEntities db = new dbRamotEntities()) { Volunteers v = db.Volunteers.Find(id); foreach (var item in category) { var c = db.Categories.FirstOrDefault(ca => ca.Id == item.Id); v.Categories.Add(c); db.SaveChanges(); } } }
public static Volunteer CastVolunteerToComon(Volunteers volunteer) { return(volunteer == null ? null : new Volunteer() { Id = volunteer.Id, Address = volunteer.Address, Age = volunteer.Age, Comments = volunteer.Comments, Email = volunteer.Email, IsActive = volunteer.IsActive, Name = volunteer.Name, Pelephone = volunteer.Pelephone, Telephone = volunteer.Telephone }); }
/// <summary> /// Update volunteer with new information, including categories. /// </summary> /// <param name="volunteer">Volunteer object</param> /// <param name="categories">List of categories</param> public static void UpdateVolunteer(Volunteer volunteer, Category[] categories) { Volunteers v = Mapper.CastVolunteer(volunteer); using (dbRamotEntities db = new dbRamotEntities()) { db.Volunteers.Find(volunteer.Id).Categories.Clear(); foreach (var item in categories) { var c = db.Categories.FirstOrDefault(ca => ca.Id == item.Id); db.Volunteers.Find(volunteer.Id).Categories.Add(c); } db.Entry <Volunteers>(db.Set <Volunteers>().Find(v.Id)).CurrentValues.SetValues(v); db.SaveChanges(); } }
/// <summary> /// Add volunteer to db, and categories for that volunteer. /// </summary> /// <param name="volunteer">Volunteer object</param> /// <param name="category">Category</param> /// <returns>Id of added volunteer</returns> public static int AddVolunteer(Volunteer volunteer, Category[] category) { int x = 0; Volunteers v = Mapper.CastVolunteer(volunteer); using (dbRamotEntities db = new dbRamotEntities()) { foreach (var item in category) { var c = db.Categories.FirstOrDefault(ca => ca.Id == item.Id); v.Categories.Add(c); } db.Volunteers.Add(v); db.SaveChanges(); x = db.Volunteers.Local[0].Id; } return(x); }
public static IEnumerable <Group> GetGroups(int id) { List <Group> groups = new List <Group>(); using (dbRamotEntities db = new dbRamotEntities()) { Volunteers v = db.Volunteers.Find(id); var f = db.Groups.ToList(); foreach (var g in f) { var s = g.Volunteers.ToList(); if (s.Contains(v)) { groups.Add(Mapper.CastGroupToComon(g)); } } } return(groups); }