/// <summary> /// POST adds NEW information to the user profile database. /// This effectively resets the appearance before applying those /// characteristics supplied in the request. /// </summary> private void DoExtend(AppearanceRequestData rdata) { bool created = false; bool modified = false; string newnode = String.Empty; Rest.Log.DebugFormat("{0} POST ENTRY", MsgId); //AvatarAppearance old = Rest.AvatarServices.GetUserAppearance(rdata.userProfile.ID); rdata.userAppearance = new AvatarAppearance(); // Although the following behavior is admitted by HTTP I am becoming // increasingly doubtful that it is appropriate for REST. If I attempt to // add a new record, and it already exists, then it seems to me that the // attempt should fail, rather than update the existing record. if (GetUserAppearance(rdata)) { modified = rdata.userAppearance != null; created = !modified; Rest.AvatarServices.UpdateUserAppearance(rdata.userProfile.ID, rdata.userAppearance); // Rest.UserServices.UpdateUserProfile(rdata.userProfile); } else { created = true; Rest.AvatarServices.UpdateUserAppearance(rdata.userProfile.ID, rdata.userAppearance); // Rest.UserServices.UpdateUserProfile(rdata.userProfile); } if (created) { newnode = String.Format("{0} {1}", rdata.userProfile.FirstName, rdata.userProfile.SurName); // Must include a location header with a URI that identifies the new resource. rdata.AddHeader(Rest.HttpHeaderLocation, String.Format("http://{0}{1}:{2}{3}{4}", rdata.hostname, rdata.port, rdata.path, Rest.UrlPathSeparator, newnode)); rdata.Complete(Rest.HttpStatusCodeCreated); } else { if (modified) { rdata.Complete(Rest.HttpStatusCodeOK); } else { rdata.Complete(Rest.HttpStatusCodeNoContent); } } rdata.Respond(String.Format("Appearance {0} : Normal completion", rdata.method)); }
/// <summary> /// POST adds NEW information to the user profile database. /// This effectively resets the appearance before applying those /// characteristics supplied in the request. /// </summary> private void DoExtend(AppearanceRequestData rdata) { bool created = false; bool modified = false; string newnode = String.Empty; Rest.Log.DebugFormat("{0} POST ENTRY", MsgId); //AvatarAppearance old = Rest.AvatarServices.GetUserAppearance(rdata.userProfile.ID); rdata.userAppearance = new AvatarAppearance(); // Although the following behavior is admitted by HTTP I am becoming // increasingly doubtful that it is appropriate for REST. If I attempt to // add a new record, and it already exists, then it seems to me that the // attempt should fail, rather than update the existing record. if (GetUserAppearance(rdata)) { modified = rdata.userAppearance != null; created = !modified; Rest.AvatarServices.UpdateUserAppearance(rdata.userProfile.ID, rdata.userAppearance); // Rest.UserServices.UpdateUserProfile(rdata.userProfile); } else { created = true; Rest.AvatarServices.UpdateUserAppearance(rdata.userProfile.ID, rdata.userAppearance); // Rest.UserServices.UpdateUserProfile(rdata.userProfile); } if (created) { newnode = String.Format("{0} {1}", rdata.userProfile.FirstName, rdata.userProfile.SurName); // Must include a location header with a URI that identifies the new resource. rdata.AddHeader(Rest.HttpHeaderLocation,String.Format("http://{0}{1}:{2}{3}{4}", rdata.hostname,rdata.port,rdata.path,Rest.UrlPathSeparator, newnode)); rdata.Complete(Rest.HttpStatusCodeCreated); } else { if (modified) { rdata.Complete(Rest.HttpStatusCodeOK); } else { rdata.Complete(Rest.HttpStatusCodeNoContent); } } rdata.Respond(String.Format("Appearance {0} : Normal completion", rdata.method)); }