Esempio n. 1
0
        public ServiceResult SaveProfile(GreenWerx.Models.Membership.ProfileMember p)
        {
            if (p == null)
            {
                return(ServiceResponse.Error("Invalid form sent to server."));
            }

            if (_profileMemberManager == null)
            {
                _profileMemberManager = new ProfileMemberManager(Globals.DBConnectionKey, this.GetAuthToken(Request));
            }
            var res = _profileMemberManager.Get(p.UUID);

            if (res.Code != 200)
            {
                if (string.IsNullOrWhiteSpace(p.CreatedBy))
                {
                    p.UUID = CurrentUser.UUID;
                }

                return(_profileMemberManager.Save(p));
            }
            GreenWerx.Models.Membership.ProfileMember dbProfile = (ProfileMember)res.Result;
            return(_profileMemberManager.Update(p));
        }
Esempio n. 2
0
        public ServiceResult SaveProfile(GreenWerx.Models.Membership.Profile p)
        {
            if (p == null)
            {
                return(ServiceResponse.Error("Invalid form sent to server."));
            }

            ProfileManager profileManager = new ProfileManager(Globals.DBConnectionKey, this.GetAuthToken(Request));

            if (_profileMemberManager == null)
            {
                _profileMemberManager = new ProfileMemberManager(Globals.DBConnectionKey, this.GetAuthToken(Request));
            }

            var dbProfile = profileManager.Get(p.UUID);

            if (dbProfile == null)
            {
                if (string.IsNullOrWhiteSpace(p.CreatedBy))
                {
                    p.UUID = CurrentUser.UUID;
                }

                p.Private = true;
                var res = profileManager.InsertProfile(p);
                if (res.Code != 200)
                {
                    return(ServiceResponse.Error("Failed to create profile."));
                }

                foreach (var profileMember in p.Members)
                {
                    profileMember.CreatedBy   = CurrentUser.UUID;
                    profileMember.DateCreated = DateTime.UtcNow;
                    profileMember.Private     = true;
                    profileMember.ProfileUUID = p.UUID;
                    _profileMemberManager.Save(profileMember);
                }
                profileManager.UpdateProfile(p);//this will update the cache fields
                return(res);
            }
            foreach (var profileMember in p.Members)
            {
                _profileMemberManager.Update(profileMember);
            }

            return(profileManager.UpdateProfile(p));
        }