public IHttpActionResult PutCoach(int id, CRUDviewmodel coach) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != coach.Coach_ID) { return(BadRequest()); } // db.Entry(coach).State = EntityState.Modified; using (var ctx = new Tuks_Athletics_SystemEntities()) { var curCoach = ctx.Coaches.Where(s => s.Coach_ID == coach.Coach_ID).FirstOrDefault(); if (curCoach != null) { curCoach.Name = coach.Name; curCoach.Surname = coach.Surname; curCoach.Email = coach.Email; curCoach.Description = coach.Description; } try { ctx.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CoachExists(id)) { return(NotFound()); } else { throw; } } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutFederation(int id, FederationViewModel federation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != federation.Id) { return(BadRequest()); } //db.Entry(federation).State = EntityState.Modified; using (var ctx = new Tuks_Athletics_SystemEntities()) { var existingFederation = ctx.Federations.Where(s => s.Federation_ID == federation.Id).FirstOrDefault <Federation>(); if (existingFederation != null) { existingFederation.Name = federation.Name; existingFederation.Descrption = federation.Description; } try { ctx.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!FederationExists(id)) { return(NotFound()); } else { throw; } } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutLeague(int id, LeagueViewModel league) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != league.Id) { return(BadRequest()); } //db.Entry(league).State = EntityState.Modified; using (var ctx = new Tuks_Athletics_SystemEntities()) { var existingLeague = ctx.Leagues.Where(s => s.League_ID == league.Id).FirstOrDefault <League>(); if (existingLeague != null) { existingLeague.Name = league.Name; existingLeague.Tier = league.Tier; } try { ctx.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!LeagueExists(id)) { return(NotFound()); } else { throw; } } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutDistrict(int id, DistrictViewModel district) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != district.Id) { return(BadRequest()); } //db.Entry(district).State = EntityState.Modified; using (var ctx = new Tuks_Athletics_SystemEntities()) { var existingDistrict = ctx.Districts.Where(s => s.District_ID == district.Id).FirstOrDefault <District>(); if (existingDistrict != null) { existingDistrict.Name = district.Name; existingDistrict.Province = district.Province; } try { ctx.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DistrictExists(id)) { return(NotFound()); } else { throw; } } } return(StatusCode(HttpStatusCode.NoContent)); }
public bool ChangePassword(string email, User user) { db.Configuration.ProxyCreationEnabled = false; User usr = db.Users.Where(z => z.Email == email).FirstOrDefault(); var hash = ComputeSha256Hash(user.Password); usr.User_ID = usr.User_ID; usr.Type_ID = usr.Type_ID; usr.Password = hash; usr.Name = usr.Name; usr.Surname = usr.Surname; usr.Email = usr.Email; usr.Phone_Number = usr.Phone_Number; // Guid g = Guid.NewGuid(); // db.Entry(usr).State = EntityState.Modified; //await db.SaveChangesAsync(); db.SaveChanges(); return(true); }