예제 #1
0
        public ServiceResult UpdateProfile(ProfileForm p)
        {
            if (p == null)
            {
                return(ServiceResponse.Error("Invalid form sent to server."));
            }

            UserManager userManager = new UserManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);

            TreeMon.Models.Membership.Profile dbProfile = userManager.GetCurrentProfile(p.UserUUID);
            if (dbProfile == null)
            {
                return(ServiceResponse.Error("Profile not found."));
            }

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <ProfileForm, TreeMon.Models.Membership.Profile>();
            });

            IMapper mapper = config.CreateMapper();
            var     dest   = mapper.Map <ProfileForm, TreeMon.Models.Membership.Profile>(p);

            return(userManager.LogUserProfile(dest));
        }
예제 #2
0
        public ServiceResult GetUserProfile()
        {
            UserManager userManager = new UserManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);

            TreeMon.Models.Membership.Profile profile = userManager.GetCurrentProfile(GetUser(Request.Headers?.Authorization?.Parameter)?.UUID);

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <TreeMon.Models.Membership.Profile, ProfileForm>();
            });

            IMapper mapper = config.CreateMapper();
            var     p      = mapper.Map <TreeMon.Models.Membership.Profile, ProfileForm>(profile);

            if (p == null)
            {
                p             = new ProfileForm();
                p.UserUUID    = CurrentUser.UUID;
                p.AccountUUID = CurrentUser.AccountUUID;
            }

            return(ServiceResponse.OK("", p));
        }