public HttpResponseMessage Put([FromBody] InserUsersRequest data) { return(Execute(delegate { if (data.Profiles == null || !data.Profiles.Any()) { throw new ArgumentException("No UserProfile change data submitted"); } if (data.Profiles.Any(d => d == null || string.IsNullOrWhiteSpace(d.UserName))) { throw new ArgumentException("User data is incomplete"); } if (SessionGlobal.CurrentUser == null || SessionGlobal.CurrentUser.Identity == null || !SessionGlobal.CurrentUser.Identity.IsAuthenticated) { throw new Exception("Current user is not authorized to make changes to profile"); } //First, lets identify if similar profile exists Expression <Func <IUserProfile, bool> > ret = x => false; var expParam = ret.Parameters.First(); Expression res = ret.Body; foreach (var ru in data.Profiles) { res = Expression.OrElse(Expression.Invoke(ToPartialLambda(ru, expParam), expParam), Expression.Invoke(ret, expParam)); } var similar = SecurityDb.FindUserProfile(new UserProfileDiscriminator() { Filter = Expression.Lambda <Func <IUserProfile, bool> >(res, expParam) }); //First resolve conflicts if (similar.Any()) { switch (data.ConflictResolutionStartegy) { case InserUsersConflictStrategy.Default: return Request.CreateResponse(HttpStatusCode.Conflict, similar.Select(x => x.UserProfile)); //case InserUsersConflictStrategy.ForceCreate: // //Now we can insert new profiles // SecurityDb.InsertUserProfile(similar.Select(d => // new ExtendedUserProfileContract() { // UserProfile = d // , // }).ToArray()); // break; } } //Second insert the rest return Request.CreateResponse(HttpStatusCode.Accepted); })); }
public void TestUpdateUserProfile() { var res = SecurityDb.FindUserProfile(null).First(); res.UserProfile.EmailId = "*****@*****.**"; SecurityDb.UpdateUserProfile(new UserProfileContract[] { res }, res.UserProfile.UserId, true); res = SecurityDb.FindUserProfile(new UserProfileDiscriminator() { Filter = x => x.UserId == res.UserProfile.UserId }).First(); }
public void TestFindUserProfile() { var res = SecurityDb.FindUserProfile(null); }