public async Task <IActionResult> PutUserSponsor(int id, UserSponsor userSponsor) { if (id != userSponsor.SponsorId) { return(BadRequest()); } _context.Entry(userSponsor).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserSponsorExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <UserSponsor> > PostUserSponsor(UserSponsor userSponsor) { _context.UserSponsor.Add(userSponsor); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (UserSponsorExists(userSponsor.SponsorId)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetUserSponsor", new { id = userSponsor.SponsorId }, userSponsor)); }
public bool AssignSponsorToUser(List <string> sponsors, int userid) { bool isValid = true; bool isSuccessful = true; //Check whether sponsor is already assigned to the user try { foreach (string s in sponsors) { int si = int.Parse(s); if (usersponsorrepo.Find(model => (model.SponsorID == si && model.UserID == userid)) != null) { isValid = false; } if (isValid) { UserSponsor us = new UserSponsor(); us.UserID = userid; us.SponsorID = si; usersponsorrepo.Create(us); } else { isSuccessful = false; } } } catch (Exception e) { isSuccessful = false; throw e; } return(isSuccessful); }