public JsonResult SaveChanges(string Name, string Sectors, string Terms) { _listUsers.Read(); List <int> ListSectorsID = Sectors.Split(',').ToList().Select(s => int.Parse(s)).ToList(); User usr = _listUsers.Where(u => u.Name == Name).FirstOrDefault(); if (usr == null) { usr = new User(); usr.Name = Name; usr.Save(); usr.GetID(); UserInfos userInfo = new UserInfos(); userInfo.Terms = Terms.Equals("true"); userInfo.UserID = usr.UserID; userInfo.Insert(); } foreach (int sector in ListSectorsID) { _listUserSectors.Add(new UserSectors { UserID = usr.UserID, SectorID = sector }); } _listUserSectors.Save(); return(Json(ListSectorsID)); }