Beispiel #1
0
        public async Task <UserSettingsModel> AddAsync([FromBody] UserSettingsModel model)
        {
            Entities.UserSetting objToSave = new Entities.UserSetting();
            objToSave.agencyid   = ApplicationContext.CurrentUser.SubscriberId;
            objToSave.ColumnSize = 0;
            objToSave.Controls   = true;
            objToSave.memberid   = ApplicationContext.CurrentUser.MemberId;
            objToSave.Theme      = 0;
            var json = JsonConvert.SerializeObject(model);

            objToSave.ModelJson = json;
            UserSettingsModel userSettingToRetrieve;
            var getUserSettings = await UnitOfWork.UserSettingsRepository.GetByAsync(x => x.memberid == ApplicationContext.CurrentUser.MemberId);

            if (getUserSettings != null)
            {
                if (getUserSettings.ModelJson.Equals(string.Empty))
                {
                    var userSetting = await UnitOfWork.UserSettingsRepository.InsertAsync(objToSave);

                    userSettingToRetrieve = JsonConvert.DeserializeObject <UserSettingsModel>(userSetting.ModelJson);
                }
                else
                {
                    objToSave.Id = getUserSettings.Id;
                    bool success = await UnitOfWork.UserSettingsRepository.UpdateAsync(objToSave);

                    userSettingToRetrieve = JsonConvert.DeserializeObject <UserSettingsModel>(objToSave.ModelJson);
                }
            }
            else
            {
                var userSetting = await UnitOfWork.UserSettingsRepository.InsertAsync(objToSave);

                if (userSetting != null)
                {
                    userSettingToRetrieve = JsonConvert.DeserializeObject <UserSettingsModel>(userSetting.ModelJson);
                }
                else
                {
                    userSettingToRetrieve = Mapper.Map <UserSettingsModel>(UnitOfWork.UserSettingsRepository.GetDefaultSettings());
                }
            }
            return(userSettingToRetrieve);
        }
Beispiel #2
0
        public async Task <IActionResult> UpdateAsync([FromBody] UserSettingsModel model)
        {
            var setting = Mapper.Map <UserSettingsModel, UserSetting>(model);

            Entities.UserSetting objToSave = new Entities.UserSetting();
            objToSave.agencyid   = ApplicationContext.CurrentUser.SubscriberId;
            objToSave.ColumnSize = 0;
            objToSave.Controls   = true;
            objToSave.memberid   = ApplicationContext.CurrentUser.MemberId;
            objToSave.Theme      = 0;
            var json = JsonConvert.SerializeObject(setting);

            objToSave.ModelJson = json;
            //var userSetting = await UnitOfWork.UserSettingsRepository.InsertAsync(objToSave);
            bool success = await UnitOfWork.UserSettingsRepository.UpdateAsync(objToSave);

            return(new ObjectResult(success));
        }