public async Task <IActionResult> OnPostUpdateAsync(int id) { var devoteeToUpdate = await _context.DevoteeSkills.FirstOrDefaultAsync(x => x.DevoteeId == id); if (devoteeToUpdate == null) { return(NotFound()); } // var skills = Enum.GetNames(typeof(Skill)); var count = skills.Length; List <string> learning = new List <string>(); List <string> teaching = new List <string>(); List <string> usingInYatra = new List <string>(); List <string> haveTheSkills = new List <string>(); for (var i = 0; i < count; i++) { var x = i.ToString(); if (Learning[i]) { learning.Add(x); } if (Teaching[i]) { teaching.Add(x); } if (UsingInYatra[i]) { usingInYatra.Add(x); } if (HaveTheSkills[i]) { haveTheSkills.Add(x); } } DevoteeSkill devoteeSkill = new DevoteeSkill(); DevoteeSkill = devoteeSkill; DevoteeSkill.DevoteeId = id; DevoteeSkill.Learning = string.Join(',', learning); DevoteeSkill.Teaching = string.Join(',', teaching); DevoteeSkill.UsingInYatra = string.Join(',', usingInYatra); DevoteeSkill.HaveTheSkills = string.Join(',', haveTheSkills); DevoteeSkill.SpecialSkills = SpecialSkills; // if (await TryUpdateModelAsync <DevoteeSkill>( devoteeToUpdate, "devotee", s => s.DevoteeId, s => s.Learning, s => s.Teaching, s => s.UsingInYatra, s => s.HaveTheSkills, s => s.SpecialSkills)) { await _context.SaveChangesAsync(); } return(await OnGetAsync(DevoteeSkill.DevoteeId)); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync(int id) { if (!ModelState.IsValid) { return(Page()); } var skills = Enum.GetNames(typeof(Skill)); var count = skills.Length; List <string> learning = new List <string>(); List <string> teaching = new List <string>(); List <string> usingInYatra = new List <string>(); List <string> haveTheSkills = new List <string>(); for (var i = 0; i < count; i++) { var x = i.ToString(); if (Learning[i]) { learning.Add(x); } if (Teaching[i]) { teaching.Add(x); } if (UsingInYatra[i]) { usingInYatra.Add(x); } if (HaveTheSkills[i]) { haveTheSkills.Add(x); } } DevoteeSkill devoteeSkill = new DevoteeSkill(); DevoteeSkill = devoteeSkill; DevoteeSkill.DevoteeId = id; DevoteeSkill.Learning = string.Join(',', learning); DevoteeSkill.Teaching = string.Join(',', teaching);; DevoteeSkill.UsingInYatra = string.Join(',', usingInYatra);; DevoteeSkill.HaveTheSkills = string.Join(',', haveTheSkills);; DevoteeSkill.SpecialSkills = SpecialSkills; _context.DevoteeSkills.Add(DevoteeSkill); await _context.SaveChangesAsync(); return(await OnGetAsync(DevoteeSkill.DevoteeId)); }
public void SetAllLists(DevoteeSkill ds) { var skills = Enum.GetNames(typeof(Skill)); var count = skills.Length; Learning = new List <bool>(new bool[count]); Teaching = new List <bool>(new bool[count]); UsingInYatra = new List <bool>(new bool[count]); HaveTheSkills = new List <bool>(new bool[count]); List <int> learningList = ds.Learning.Length > 1 ? ds.Learning.Split(',').Select(Int32.Parse).ToList() : (ds.Learning == string.Empty ? null : new List <int> { Int32.Parse(ds.Learning) }); List <int> teachingList = ds.Teaching.Length > 1 ? ds.Teaching.Split(',').Select(Int32.Parse).ToList() : (ds.Teaching == string.Empty ? null : new List <int> { Int32.Parse(ds.Teaching) }); List <int> usingInYatraList = ds.UsingInYatra.Length > 1 ? ds.UsingInYatra.Split(',').Select(Int32.Parse).ToList() : (ds.UsingInYatra == string.Empty ? null : new List <int> { Int32.Parse(ds.UsingInYatra) }); List <int> haveTheSkillsList = ds.HaveTheSkills.Length > 1 ? ds.HaveTheSkills.Split(',').Select(Int32.Parse).ToList() : (ds.HaveTheSkills == string.Empty ? null : new List <int> { Int32.Parse(ds.HaveTheSkills) }); if (learningList != null) { SetFlags(Learning, learningList); } if (teachingList != null) { SetFlags(Teaching, teachingList); } if (usingInYatraList != null) { SetFlags(UsingInYatra, usingInYatraList); } if (haveTheSkillsList != null) { SetFlags(HaveTheSkills, haveTheSkillsList); } SpecialSkills = ds.SpecialSkills; }