Esempio n. 1
0
        public static int EditTaskConfig(TaskConfigModel request, string Operator)
        {
            var taskId      = Guid.Empty;
            var result      = true;
            var operate     = default(string);
            var triggerData = request.TriggerList.Select(
                g => new TriggerTaskModel
            {
                TriggerTaskId   = g.TaskId,
                TriggerTaskName = g.TaskName,
                TriggerType     = 1,
                IsTimeout       = false
            })
                              .Union(request.DisplayTriggerList.Select(
                                         g => new TriggerTaskModel
            {
                TriggerTaskId   = g.TaskId,
                TriggerTaskName = g.TaskName,
                TriggerType     = 0,
                IsTimeout       = false
            }))
                              .Union(request.TimeoutTriggerList.Select(
                                         g => new TriggerTaskModel
            {
                TriggerTaskId   = g.TaskId,
                TriggerTaskName = g.TaskName,
                TriggerType     = 0,
                IsTimeout       = true
            }))
                              .ToList();

            foreach (var item in request.ConditionList)
            {
                if (item.ActionName.Equals("10BuyProduct"))
                {
                    var specialpara = new List <string>();
                    var data        = item.SpecialPara.Split(';').Where(g => !string.IsNullOrEmpty(g)).ToList();
                    foreach (var paraItem in data)
                    {
                        if (int.TryParse(paraItem, out var value))
                        {
                            specialpara.Add($"OR{value.ToString("D8")}");
                        }
                        else if (paraItem.StartsWith("OR"))
                        {
                            specialpara.Add(paraItem);
                        }
                    }
                    if (!specialpara.Any())
                    {
                        return(0);
                    }
                    item.SpecialPara = string.Join(";", specialpara);
                }
            }
            using (var dbHelper = Component.Common.DbHelper.CreateDefaultDbHelper())
            {
                dbHelper.BeginTransaction();
                if (request.TaskId == Guid.Empty)
                {
                    request.TaskId = Guid.NewGuid();
                    taskId         = request.TaskId;
                    operate        = "Create";
                    result         = DalTask.AddTaskConfig(request, Operator, dbHelper);
                    if (result)
                    {
                        result = DalTask.AddCondition(request.TaskId, request.ConditionList, dbHelper);
                    }
                    if (result && triggerData.Any())
                    {
                        result = DalTask.AddTriggerTask(request.TaskId, triggerData, dbHelper);
                    }
                    if (result && request.CouponList.Any())
                    {
                        result = DalTask.AddCoupon(request.TaskId, request.CouponList, dbHelper);
                    }
                }
                else
                {
                    taskId  = request.TaskId;
                    operate = "Update";
                    result  = DalTask.UpdateTaskConfig(request, dbHelper);
                    if (result)
                    {
                        result = DalTask.EditCoupon(request.TaskId, request.CouponList, dbHelper);
                    }
                    if (result)
                    {
                        result = DalTask.UpdateTriggerTask(request.TaskId, triggerData, dbHelper);
                    }
                    if (result)
                    {
                        result = DalTask.DeleteCondition(request.TaskId, dbHelper);
                        if (result)
                        {
                            result = DalTask.AddCondition(request.TaskId, request.ConditionList, dbHelper);
                        }
                    }
                }
                if (result)
                {
                    result = RefreshCache();
                    dbHelper.Commit();
                }
                else
                {
                    dbHelper.Rollback();
                    return(2);
                }
                if (result)
                {
                    TaskOprLog(request.TaskId, Operator, operate, JsonConvert.SerializeObject(request));
                }
                return(result ? 1 : 3);
            }
        }