Exemplo n.º 1
0
        public void DeleteByPollId(int pollId)
        {
            _repository.Delete(Q.Where(Attr.PollId, pollId));

            FieldManager.ItemRepository.DeleteByPollId(pollId);

            FieldManager.ClearCache(pollId);
        }
Exemplo n.º 2
0
        public void DeleteByFormId(int formId)
        {
            _repository.Delete(Q.Where(Attr.FormId, formId));

            FieldManager.ItemRepository.DeleteByFormId(formId);

            FieldManager.ClearCache(formId);
        }
Exemplo n.º 3
0
        public void Update(FieldInfo info, bool updateItems)
        {
            _repository.Update(info);

            if (updateItems)
            {
                FieldManager.ItemRepository.DeleteByFieldId(info.Id);
                FieldManager.ItemRepository.InsertItems(info.PollId, info.Id, info.Items);
            }

            FieldManager.ClearCache(info.PollId);
        }
Exemplo n.º 4
0
        public void Delete(int pollId, int fieldId)
        {
            if (fieldId == 0)
            {
                return;
            }

            _repository.Delete(fieldId);

            FieldManager.ItemRepository.DeleteByFieldId(fieldId);

            FieldManager.ClearCache(pollId);
        }
Exemplo n.º 5
0
        public static int Insert(int siteId, FieldInfo fieldInfo)
        {
            fieldInfo.Taxis = GetMaxTaxis(fieldInfo.FormId) + 1;

            var sqlString = $@"INSERT INTO {TableName}
(
    {nameof(FieldInfo.FormId)}, 
    {nameof(FieldInfo.Taxis)},
    {nameof(FieldInfo.Title)},
    {nameof(FieldInfo.Description)},
    {nameof(FieldInfo.PlaceHolder)},
    {nameof(FieldInfo.FieldType)},
    {nameof(FieldInfo.Validate)},
    {nameof(FieldInfo.Settings)}
) VALUES (
    @{nameof(FieldInfo.FormId)}, 
    @{nameof(FieldInfo.Taxis)},
    @{nameof(FieldInfo.Title)},
    @{nameof(FieldInfo.Description)},
    @{nameof(FieldInfo.PlaceHolder)},
    @{nameof(FieldInfo.FieldType)},
    @{nameof(FieldInfo.Validate)},
    @{nameof(FieldInfo.Settings)}
)";

            var parameters = new []
            {
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.FormId), fieldInfo.FormId),
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.Taxis), fieldInfo.Taxis),
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.Title), fieldInfo.Title),
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.Description), fieldInfo.Description),
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.PlaceHolder), fieldInfo.PlaceHolder),
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.FieldType), fieldInfo.FieldType),
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.Validate), fieldInfo.Validate),
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.Settings), fieldInfo.Settings)
            };

            var id = Context.DatabaseApi.ExecuteNonQueryAndReturnId(TableName, nameof(FieldInfo.Id), Context.ConnectionString, sqlString, parameters);

            FieldItemDao.InsertItems(fieldInfo.FormId, id, fieldInfo.Items);

            var formInfo = FormManager.GetFormInfo(siteId, fieldInfo.FormId);
            var list     = FormUtils.StringCollectionToStringList(formInfo.Additional.ListAttributeNames);

            list.Add(fieldInfo.Title);
            formInfo.Additional.ListAttributeNames = FormUtils.ObjectCollectionToString(list);
            FormDao.Update(formInfo);

            FieldManager.ClearCache();
            return(id);
        }
Exemplo n.º 6
0
        private static void SetTaxis(int id, int taxis)
        {
            var sqlString = $"UPDATE {TableName} SET Taxis = @Taxis WHERE Id = @Id";

            var parms = new []
            {
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.Taxis), taxis),
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.Id), id)
            };

            Context.DatabaseApi.ExecuteNonQuery(Context.ConnectionString, sqlString, parms);

            FieldManager.ClearCache();
        }
Exemplo n.º 7
0
        public static void DeleteByFormId(int formId)
        {
            string sqlString = $"DELETE FROM {TableName} WHERE {nameof(FieldInfo.FormId)} = @{nameof(FieldInfo.FormId)}";

            var parms = new[]
            {
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.FormId), formId)
            };

            Context.DatabaseApi.ExecuteNonQuery(Context.ConnectionString, sqlString, parms);

            FieldItemDao.DeleteByFormId(formId);

            FieldManager.ClearCache();
        }
Exemplo n.º 8
0
        public void Insert(int siteId, FieldInfo fieldInfo)
        {
            fieldInfo.Taxis = GetMaxTaxis(fieldInfo.PollId) + 1;

            fieldInfo.Id = _repository.Insert(fieldInfo);

            FieldManager.ItemRepository.InsertItems(fieldInfo.PollId, fieldInfo.Id, fieldInfo.Items);

            var formInfo = PollManager.GetPollInfo(siteId, fieldInfo.PollId);
            var list     = PollUtils.StringCollectionToStringList(formInfo.ListAttributeNames);

            list.Add(fieldInfo.Title);
            formInfo.ListAttributeNames = PollUtils.ObjectCollectionToString(list);
            PollManager.Repository.Update(formInfo);

            FieldManager.ClearCache(fieldInfo.PollId);
        }
Exemplo n.º 9
0
        public IHttpActionResult Delete()
        {
            try
            {
                var request = Context.AuthenticatedRequest;

                var formInfo = FormManager.GetFormInfoByGet(request);
                if (formInfo == null)
                {
                    return(NotFound());
                }
                if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(formInfo.SiteId, FormUtils.MenuFormsPermission))
                {
                    return(Unauthorized());
                }

                var fieldId = request.GetQueryInt("fieldId");
                FieldManager.Repository.Delete(formInfo.Id, fieldId);
                FieldManager.ClearCache(formInfo.Id);

                var list = new List <object>();
                foreach (var fieldInfo in FieldManager.GetFieldInfoList(formInfo.Id))
                {
                    list.Add(new
                    {
                        fieldInfo.Id,
                        fieldInfo.Title,
                        InputType = FieldManager.GetFieldTypeText(fieldInfo.FieldType),
                        fieldInfo.Validate,
                        fieldInfo.Taxis
                    });
                }

                return(Ok(new
                {
                    Value = list
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemplo n.º 10
0
        public static void Update(FieldInfo info, bool updateItems)
        {
            var sqlString = $@"UPDATE {TableName} SET
                {nameof(FieldInfo.FormId)} = @{nameof(FieldInfo.FormId)}, 
                {nameof(FieldInfo.Taxis)} = @{nameof(FieldInfo.Taxis)}, 
                {nameof(FieldInfo.Title)} = @{nameof(FieldInfo.Title)},
                {nameof(FieldInfo.Description)} = @{nameof(FieldInfo.Description)},
                {nameof(FieldInfo.PlaceHolder)} = @{nameof(FieldInfo.PlaceHolder)},
                {nameof(FieldInfo.FieldType)} = @{nameof(FieldInfo.FieldType)},
                {nameof(FieldInfo.Validate)} = @{nameof(FieldInfo.Validate)},
                {nameof(FieldInfo.Settings)} = @{nameof(FieldInfo.Settings)}
            WHERE {nameof(FieldInfo.Id)} = @{nameof(FieldInfo.Id)}";

            var updateParms = new []
            {
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.FormId), info.FormId),
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.Taxis), info.Taxis),
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.Title), info.Title),
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.Description), info.Description),
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.PlaceHolder), info.PlaceHolder),
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.FieldType), info.FieldType),
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.Validate), info.Validate),
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.Settings), info.Additional.ToString()),
                Context.DatabaseApi.GetParameter(nameof(FieldInfo.Id), info.Id)
            };

            Context.DatabaseApi.ExecuteNonQuery(Context.ConnectionString, sqlString, updateParms);

            if (updateItems)
            {
                FieldItemDao.DeleteByFieldId(info.Id);
                FieldItemDao.InsertItems(info.FormId, info.Id, info.Items);
            }

            FieldManager.ClearCache();
        }