public async Task <ActionResult> Update(ProfileInterop pd) { try { await WebApi(WebApiMethod.Put, "api/Profile/" + pd.Id.ToString(), pd); return(RedirectToAction("Index")); } // Authentication failure? catch (Exception e) { return(RedirectToAction("Index", "Home")); } }
public async Task <ActionResult> Create(ProfileInterop pd) { try { await WebApi(WebApiMethod.Post, "api/Profile/1", pd); return(RedirectToAction("Index", "Home")); } // Authentication failure? catch (Exception e) { return(RedirectToAction("Index", "Home")); } }
Profile FromInterop(ProfileInterop pi) { Profile p = new Profile(); p.CallbackAddress = pi.CallbackAddress; p.DOB = pi.DOB; p.Email = pi.Email; p.Id = pi.Id; p.Male = pi.Male; p.Nickname = pi.Nickname; p.Password = pi.Password; p.Phone = pi.Phone; p.Tagline = pi.Tagline; p.Flags = pi.Flags; return(p); }
ProfileInterop ToInterop(Profile p) { ProfileInterop pi = new ProfileInterop(); pi.CallbackAddress = p.CallbackAddress; pi.DOB = p.DOB ?? DateTime.MinValue; pi.Email = p.Email; pi.Id = p.Id; pi.Male = p.Male; pi.Nickname = p.Nickname; pi.Password = p.Password; pi.Phone = p.Phone; pi.Tagline = p.Tagline; pi.Flags = p.Flags; return(pi); }
public IHttpActionResult PutProfile(int id, ProfileInterop newProfile) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != newProfile.Id) { return(BadRequest()); } // Change only the changed fields in the profile. // Only the fields below are changeable via the API. // Non-nullable fields must be supplied. Profile oldProfile = db.Profiles.Find(id); // TBD - Security. oldProfile.Nickname = newProfile.Nickname ?? oldProfile.Nickname; oldProfile.Email = newProfile.Email ?? oldProfile.Email; oldProfile.Password = newProfile.Password ?? oldProfile.Password; oldProfile.Phone = newProfile.Phone ?? oldProfile.Phone; oldProfile.CallbackAddress = newProfile.CallbackAddress ?? oldProfile.CallbackAddress; oldProfile.DOB = newProfile.DOB; //oldProfile.DOB = DateTime.Parse(newProfile.DobJson); oldProfile.Male = newProfile.Male ?? oldProfile.Male; db.Entry(oldProfile).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProfileExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostProfile(ProfileInterop pi) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Profile profile = FromInterop(pi); DateTime now = DateTime.Now; profile.Created = now; db.Profiles.Add(profile); // Clone the specified profile. Profile template = db.Profiles.Find(1); // Hard-coded id. foreach (Friendship f in template.Friendshipz) { Friendship clone = new Friendship(); clone.ProfileIdOwned = f.ProfileIdOwned; // Let the new profile own it. clone.ProfileIdOwner = profile.Id; db.Friendships.Add(clone); } foreach (Bubble b in template.Bubbles) { Bubble clone = new Bubble(); clone.AlertMsg = b.AlertMsg; clone.Latitude = b.Latitude; clone.Longitude = b.Longitude; clone.Name = b.Name; clone.RadiusId = b.RadiusId; clone.Active = b.Active; // Let the new profile own it. clone.ProfileId = profile.Id; db.Bubbles.Add(clone); } db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = profile.Id }, profile)); }