Beispiel #1
0
        public bool UpdateUserProfile(UserGeneralProfileInDTO user, Guid userInfoId)
        {
            try
            {
                var currentUser = _userInfoRepository.FindByID(user.UserInfoId);

                if (currentUser == null)
                {
                    return(false);
                }

                currentUser.Address    = user.Address;
                currentUser.ContactNo  = user.ContactNo;
                currentUser.Position   = user.Position;
                currentUser.ImageURL   = user.ImageURL;
                currentUser.ModifiedOn = Localization.GetUTCDateNow();
                currentUser.ModifiedBy = userInfoId;
                currentUser.Country    = user.Country;
                _userInfoRepository.Update(currentUser);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(true);
        }
Beispiel #2
0
        private async Task <JsonResult> UpdateUserProfile(UserGeneralProfileInDTO userProfile, Guid userId)
        {
            var imageUrl = string.Empty;
            var user     = (ClaimsIdentity)User.Identity;

            var organizationName = Common.GetSubDomainByContextRequest(_contextAccessor.HttpContext);

            if (!string.IsNullOrEmpty(userProfile.ImageURL) && userProfile.ImageURL.Split(',').Length > 1)
            {
                var imageContentType = userProfile.ImageURL.Split(',')[0].Split(';')[0].Split(':')[1];
                var imageFormat      = (imageContentType.Split('/')[1]);
                if (!imageFormat.Equals("jpg") &&
                    !imageFormat.Equals("jpeg") &&
                    !imageFormat.Equals("gif") &&
                    !imageFormat.Equals("png"))
                {
                    return(Json(new { success = "false", message = "Invalid image format. It must be jpg, jpeg, gif or png format." }));
                }

                userProfile.ImageURL = userProfile.ImageURL.Replace(" ", "+");

                var imageBlob = Convert.FromBase64String(userProfile.ImageURL.Split(',')[1]);

                if (imageBlob.Length > 1000000)
                {
                    return(Json(new { success = "false", message = "Image file size is exceeded to 1MB." }));
                }

                imageUrl = _azureService.UploadProfileImage(imageBlob, String.Format("{0}.{1}", userProfile.UserInfoId, "png"), organizationName);
            }
            else
            {
                imageUrl = (userProfile.ImageURL ?? string.Empty).Split('?').First();
            }

            //imageUrl = Common.AddTimestampToLink(imageUrl,Localization.GetUTCDateNow());
            userProfile.ImageURL = imageUrl;

            if (!string.IsNullOrEmpty(imageUrl))
            {
                imageUrl             = String.Format("{0}?v={1}", imageUrl, Localization.GetUTCDateNow().ToString("yyyyMMddHHmmssffff"));
                userProfile.ImageURL = imageUrl;
            }

            try
            {
                _userService.UpdateUserProfile(userProfile, userId);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(Json(new { success = "true", newImageUrl = imageUrl }));
        }
Beispiel #3
0
        public async Task <JsonResult> UpdateUserProfile(Guid userId, [FromBody] UserGeneralProfileInDTO userProfile)
        {
            var identity   = _contextAccessor.HttpContext.User.Identity;
            var userInfoId = Security.GetUserInfoId(identity);

            if (userProfile == null || userId == null)
            {
                throw new Exception("Something is missing in the payload or Id");
            }

            return(await UpdateUserProfile(userProfile, userId));
        }