Ejemplo n.º 1
0
        protected bool CreateUser(string userid, string name, UserIDType userType)
        {
            JObject userData = new JObject();

            userData[CommonConst.CommonField.USER_ID]   = userData[CommonConst.CommonField.DATA_KEY] = userid;
            userData[CommonConst.CommonField.USER_TYPE] = userType.ToString();

            var updateFilter = userData.ToString();

            userData[CommonConst.CommonField.DISPLAY_ID]        = CommonUtility.GetNewID();
            userData[CommonConst.CommonField.IS_ENABLED]        = true;
            userData[CommonConst.CommonField.NAME]              = name;
            userData[CommonConst.CommonField.IS_EMAIL_VALIDATE] = false;
            userData[CommonConst.CommonField.IS_PHONE_VALIDATE] = false;
            var userGroup = AppSettingService.GetAppSetting(ModuleAppConsts.Field.DEFAULT_USER_GROUPS_APP_SETTING_KEY);

            Logger.Debug("userGroup setting data", userGroup);
            if (userGroup == null)
            {
                throw new Exception("User Group setting not found in AppSettings");
            }
            if (userGroup[CommonConst.CommonField.DATA] == null || userGroup[CommonConst.CommonField.DATA][CommonConst.CommonField.USER_GROUPS] == null)
            {
                throw new Exception("User Groups not found in AppSettings");
            }
            userData[CommonConst.CommonField.USER_GROUPS] = (userGroup[CommonConst.CommonField.DATA][CommonConst.CommonField.USER_GROUPS] as JArray);
            return(DBProxy.Write(CommonConst.Collection.USERS, userData, updateFilter, true));
        }
Ejemplo n.º 2
0
        public JObject AdminUpdate()
        {
            try
            {
                Logger.Debug("Enter to UpdateUserInfo.AdminUpdate");
                JObject request = HttpProxy.GetRequestBody <JObject>();
                if (request == null)
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }
                string userId = string.Empty;
                if (request[CommonConst.CommonField.USER_ID] != null)
                {
                    userId = request[CommonConst.CommonField.USER_ID].ToString();
                }
                if (string.IsNullOrEmpty(userId))
                {
                    Logger.Error(string.Format("Error in  UpdateUserInfo.AdminUpdate: {0}", "User id empty"));
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }

                JObject updateFilter = new JObject();
                updateFilter[CommonConst.CommonField.USER_ID] = userId;

                if (request[ModuleAppConsts.Field.USER_INFO] != null && (request[ModuleAppConsts.Field.USER_INFO] as JArray).Count > 0)
                {
                    var userInfo = request[ModuleAppConsts.Field.USER_INFO][0] as JObject;
                    Logger.Debug("Updating User Info", userInfo);
                    var dbresponse = DBProxy.Update(CommonConst.Collection.USER_INFO, updateFilter.ToString(), userInfo, true, MergeArrayHandling.Replace);
                    if (dbresponse == 0)
                    {
                        Logger.Error(string.Format("Error in  UpdateUserInfo.AdminUpdate: {0}, collection {1}", "Error in updating data in db", CommonConst.Collection.USER_INFO));
                        return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                    }
                }

                JObject userdata = new JObject();
                userdata[CommonConst.CommonField.PHONE] = request[CommonConst.CommonField.PHONE];
                userdata[CommonConst.CommonField.EMAIL] = request[CommonConst.CommonField.EMAIL];
                userdata[CommonConst.CommonField.NAME]  = request[CommonConst.CommonField.NAME];

                Logger.Debug("Updating User", userdata);
                if (DBProxy.Write(CommonConst.Collection.USERS, userdata, updateFilter.ToString(), false, MergeArrayHandling.Union))
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, updateFilter));
                }
                else
                {
                    Logger.Error(string.Format("Error in  UpdateUserInfo.AdminUpdate: {0}, collection {1}", "Error in updating data in db", CommonConst.Collection.USERS));
                    return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("Error in  UpdateUserInfo.AdminUpdate: {0}", ex.Message), ex);
                return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
            }
        }
Ejemplo n.º 3
0
        private string  UploadFile(string galleryId, UserModel user, string fileName, IKeyValueStorage keyValueStorage)
        {
            FileInfo fi = new FileInfo(fileName);

            Logger.Debug(string.Format("Getting File Data"));

            byte[] fileData = _fileUploader.GetFileData(fileName);
            using (Bitmap image = ImageGalleryHelper.GetImageBitmapFromByte(fileData))
            {
                Logger.Debug(string.Format("Getting file Hash"));
                var fileModel = new FileModel()
                {
                    file_hash = Hashing.GetFileHash(fileData), file_paths = new List <string>()
                };
                JObject fileFilter = new JObject();
                fileFilter[ImageProcessor.FILE_HASH] = fileModel.file_hash;
                if (DBProxy.FirstOrDefault(ImageProcessor.MYPHOTO_COLLECTION, fileFilter.ToString()) == null)
                {
                    Logger.Debug(string.Format("CreateFileDataJObject"));
                    var imageJObjectData = ImageGalleryHelper.CreateFileDataJObject(fileModel, string.Empty, image, keyValueStorage);
                    imageJObjectData[CommonConst.CommonField.DISPLAY_ID] = CommonUtility.GetNewID();
                    imageJObjectData[ImageProcessor.OWNER] = user.user_id;
                    DBProxy.Write(ImageProcessor.MYPHOTO_COLLECTION, imageJObjectData);
                }

                var filter = new JObject();
                filter[CommonConst.CommonField.DISPLAY_ID] = galleryId;
                Logger.Debug(string.Format("Getting gallery "));
                var galleryData = DBProxy.FirstOrDefault(ImageProcessor.MYPHOTO_GALLERY_COLLECTION, filter.ToString());
                if (galleryData == null)
                {
                    galleryData = new JObject();
                    galleryData[ImageProcessor.FILE_HASHS] = new JArray();
                    (galleryData[ImageProcessor.FILE_HASHS] as JArray).Add(fileModel.file_hash);
                    galleryData[ImageProcessor.GALLERY_THUMBNAIL] = fileModel.file_hash;
                    galleryData[ImageProcessor.OWNER]             = user.user_id;
                    galleryData[ImageProcessor.AUTH_USERS]        = new JArray();
                    (galleryData[ImageProcessor.AUTH_USERS] as JArray).Add(user.user_id);
                }
                else
                {
                    if (galleryData[ImageProcessor.FILE_HASHS] == null)
                    {
                        galleryData[ImageProcessor.FILE_HASHS] = new JArray();
                    }
                    Logger.Debug(string.Format("Adding file to collection "));
                    (galleryData[ImageProcessor.FILE_HASHS] as JArray).Insert(0, fileModel.file_hash);
                }
                galleryData[ImageProcessor.FILES_COUNT] = (galleryData[ImageProcessor.FILE_HASHS] as JArray).Count;

                DBProxy.Update(ImageProcessor.MYPHOTO_GALLERY_COLLECTION, filter.ToString(), galleryData, false, MergeArrayHandling.Replace);

                return(fileModel.file_hash);
            }
        }
Ejemplo n.º 4
0
        private bool ResetPass(UserModel requestUser, string password)
        {
            JObject userData = new JObject();

            userData[CommonConst.CommonField.USER_ID]   = userData[CommonConst.CommonField.DATA_KEY] = requestUser.user_id;
            userData[CommonConst.CommonField.USER_TYPE] = requestUser.user_type;

            var filter = userData.ToString();

            userData[CommonConst.CommonField.PASSWORD] = EncryptionService.GetHash(password);

            return(DBProxy.Write(CommonConst.Collection.USERS, userData, filter));
        }
Ejemplo n.º 5
0
        public JObject Create()
        {
            try
            {
                var user = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY);
                if (user == null)
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._401_UNAUTHORIZED));
                }

                var requestBody = HttpProxy.GetRequestBody <JObject>();
                if (requestBody == null)
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }
                if (requestBody[ImageProcessor.DISPLAY_NAME] == null || requestBody[ImageProcessor.DESCRIPTION] == null || requestBody[ImageProcessor.AUTH_USERS] == null)
                {
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }

                JObject newAblum = new JObject();
                newAblum[CommonConst.CommonField.DISPLAY_ID] = CommonUtility.GetNewID();
                newAblum[CommonConst.CommonField.NAME]       = string.Format("{0}-{1}", user.name, newAblum[CommonConst.CommonField.DISPLAY_ID].ToString());
                newAblum[ImageProcessor.DISPLAY_NAME]        = requestBody[ImageProcessor.DISPLAY_NAME].ToString();
                newAblum[ImageProcessor.FILES_COUNT]         = 0;
                newAblum[ImageProcessor.DESCRIPTION]         = requestBody[ImageProcessor.DESCRIPTION].ToString();
                newAblum[ImageProcessor.AUTH_USERS]          = new JArray();
                foreach (var e in (requestBody[ImageProcessor.AUTH_USERS] as JArray))
                {
                    (newAblum[ImageProcessor.AUTH_USERS] as JArray).Add(e.ToString());
                }
                newAblum[ImageProcessor.OWNER] = user.user_id;
                DBProxy.Write(ImageProcessor.MYPHOTO_GALLERY_COLLECTION, newAblum);
                return(ResponseBuilder.CreateReponse(CommonConst._1_SUCCESS, newAblum));
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
                return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
            }
        }
Ejemplo n.º 6
0
        private bool CreateUser(UserModel user, string password)
        {
            JObject userData = new JObject();

            userData[CommonConst.CommonField.DISPLAY_ID] = CommonUtility.GetNewID();
            userData[CommonConst.CommonField.USER_ID]    = userData[CommonConst.CommonField.DATA_KEY] = user.user_id;
            userData[CommonConst.CommonField.USER_TYPE]  = user.user_type;
            userData[CommonConst.CommonField.PASSWORD]   = EncryptionService.GetHash(password);
            userData[CommonConst.CommonField.IS_ENABLED] = true;

            if (user.user_type == UserIDType.PhoneNumber.ToString())
            {
                userData[CommonConst.CommonField.PHONE]             = user.user_id;
                userData[CommonConst.CommonField.NAME]              = user.user_id;
                userData[CommonConst.CommonField.IS_PHONE_VALIDATE] = (true && IsOTPCheckEnable());
            }
            else if (user.user_type == UserIDType.Email.ToString())
            {
                userData[CommonConst.CommonField.EMAIL]             = user.user_id;
                userData[CommonConst.CommonField.NAME]              = user.user_id;
                userData[CommonConst.CommonField.IS_EMAIL_VALIDATE] = (true && IsOTPCheckEnable());
            }

            var userGroup = AppSettingService.GetAppSetting(ModuleAppConsts.Field.DEFAULT_USER_GROUPS_APP_SETTING_KEY);

            Logger.Debug("userGroup setting data", userGroup);
            if (userGroup == null)
            {
                throw new Exception("User Group setting not found in AppSettings");
            }
            if (userGroup[CommonConst.CommonField.DATA] == null || userGroup[CommonConst.CommonField.DATA][CommonConst.CommonField.USER_GROUPS] == null)
            {
                throw new Exception("User Groups not found in AppSettings");
            }
            userData[CommonConst.CommonField.USER_GROUPS] = (userGroup[CommonConst.CommonField.DATA][CommonConst.CommonField.USER_GROUPS] as JArray);
            return(DBProxy.Write(CommonConst.Collection.USERS, userData));
        }
Ejemplo n.º 7
0
        public JObject Update()
        {
            try
            {
                Logger.Debug(string.Format("Enter to UpdateContent.Update, SessionProvider:{0}", (SessionProvider == null ? "null" : "OK")));
                UserModel user = SessionProvider.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY);

                if (user == null)
                {
                    Logger.Info(string.Format("Error in UpdateContent.Update: {0}", "user session is null"));
                    return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                }
                JObject request = HttpProxy.GetRequestBody <JObject>();
                if (request == null)
                {
                    Logger.Info(string.Format("Error in UpdateContent.Update: {0}", "request object is null"));
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }
                string id         = string.Empty;
                string data       = string.Empty;
                string moduleName = string.Empty;
                if (request[CommonConst.CommonField.DISPLAY_ID] != null &&
                    request[CommonConst.CommonField.DATA] != null &&
                    request[CommonConst.CommonField.MODULE_NAME] != null

                    )
                {
                    id         = request[CommonConst.CommonField.DISPLAY_ID].ToString();
                    data       = request[CommonConst.CommonField.DATA].ToString();
                    moduleName = request[CommonConst.CommonField.MODULE_NAME].ToString();
                }

                if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(data) || string.IsNullOrEmpty(moduleName))
                {
                    Logger.Error(string.Format("Error in UpdateContent.Update: {0}", " id/data/moduleName empty"));
                    return(ResponseBuilder.CreateReponse(CommonConst._400_BAD_REQUEST));
                }
                Logger.Debug("Get   data for UpdateContent.Update", request);

                JObject updateFilter = new JObject();
                updateFilter[CommonConst.CommonField.DISPLAY_ID] = id;
                if (moduleName != _contentUpdateModuleName)
                {
                    var originalData = DBProxy.FirstOrDefault(CommonConst.Collection.STATIC_CONTECT, updateFilter.ToString());
                    if (originalData == null)
                    {
                        Logger.Error(string.Format("Error in UpdateContent.Update: {0}, collection{1}, filter {2}", "originalData is null", CommonConst.Collection.STATIC_CONTECT, updateFilter.ToString()));
                        return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                    }
                    //bool isOverride = true;
                    //bool.TryParse(originalData[CommonConst.CommonField.IS_OVERRIDE].ToString(), out isOverride);
                    //if (isOverride)
                    //{
                    //    Logger.Error(string.Format("Error in UpdateContent.Update: {0}", "isOverride parameter is true in the oroginal data"));
                    //    return ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR);
                    //}
                    originalData[CommonConst.CommonField.IS_OVERRIDE] = true;
                    originalData[CommonConst.CommonField.OVERRIDE_BY] = _contentUpdateModuleName;

                    if (DBProxy.Update(CommonConst.Collection.STATIC_CONTECT, updateFilter.ToString(), originalData) != 1)
                    {
                        Logger.Error(string.Format("Error in UpdateContent.Update: {0}", "error updating originalData"));
                        return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                    }

                    originalData[CommonConst.CommonField.DISPLAY_ID]  = CommonUtility.GetNewID();
                    originalData[CommonConst.CommonField.IS_OVERRIDE] = false;
                    originalData[CommonConst.CommonField.OVERRIDE_BY] = _contentUpdateModuleName;
                    originalData[CommonConst.CommonField.DATA]        = data;
                    originalData[_contentHistory] = new JArray();

                    JObject filterFindExistingCustomization = new JObject();
                    filterFindExistingCustomization[CommonConst.CommonField.MODULE_NAME] = _contentUpdateModuleName;
                    filterFindExistingCustomization[CommonConst.CommonField.FILE_PATH]   = originalData[CommonConst.CommonField.FILE_PATH].ToString();
                    var existingData = DBProxy.FirstOrDefault(CommonConst.Collection.STATIC_CONTECT, filterFindExistingCustomization.ToString());
                    if (existingData == null)
                    {
                        if (!DBProxy.Write(CommonConst.Collection.STATIC_CONTECT, originalData))
                        {
                            Logger.Error(string.Format("Error in UpdateContent.Update: {0}", "error adding  new data"));
                            return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                        }
                    }
                    else
                    {
                        if (!UpdateCustomContentData(existingData, user, data, filterFindExistingCustomization))
                        {
                            return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                        }
                    }
                    return(ReturnSuccess(originalData));
                }
                else
                {
                    var contentCustomData = DBProxy.FirstOrDefault(CommonConst.Collection.STATIC_CONTECT, updateFilter.ToString());
                    if (contentCustomData == null)
                    {
                        Logger.Error(string.Format("Error in UpdateContent.Update: {0}", "contentCustomData  is null"));
                        return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                    }
                    if (!UpdateCustomContentData(contentCustomData, user, data, updateFilter))
                    {
                        return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
                    }
                    return(ReturnSuccess(contentCustomData));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("Error in  UpdateContent.Update: {0}", ex.Message), ex);
                return(ResponseBuilder.CreateReponse(CommonConst._500_SERVER_ERROR));
            }
        }