public async Task <User> UpdateProfile(int id, UserForProfileUpdateDto data) { var user = await _context.Users.Include(u => u.Ambassador) .Include(u => u.Referrer) .FirstOrDefaultAsync(u => u.Id == id); user.Name = data.Name ?? user.Name; user.Gender = data.Gender ?? user.Gender; user.MobileNumber = data.MobileNumber ?? user.MobileNumber; var categoryId = data.CategoryId ?? user.CategoryId.ToString(); var institutionId = data.InstitutionId ?? user.InstitutionId; user.CategoryId = int.Parse(categoryId); if (categoryId == "2") { user.InstitutionId = null; if (await _context.SaveChangesAsync() > 0) { return(user); } throw new DataInvalidException("No changes to update. Please re-check the details"); } if (institutionId == 0) //Adds new college or school { switch (user.Category) { case "college": { var college = await _institution.AddCollege(data.InstitutionName); user.InstitutionId = college.Id; break; } case "school": { var school = await _institution.AddSchool(data.InstitutionName); user.InstitutionId = school.Id; break; } } } else { user.InstitutionId = institutionId; } if (await _context.SaveChangesAsync() > 0) { return(user); } throw new DataInvalidException("No changes to update. Please re-check the details"); }
public async Task <ActionResult> AddSchool(DataForAddingSchoolDto data) { var school = await _repo.AddSchool(data.Name); return(Ok(school)); }