예제 #1
0
        public ICase Create(string appId, string type, string text)
        {
            IStatus status = StatusBLL.Get(appId);

            status = status == null
                         ? StatusBLL.Create(appId, JobStatus.HasCase.ToLabel())
                         : StatusBLL.Update(status, JobStatus.HasCase.ToLabel());

            return(CaseBLL.Create(appId, type, text));
        }
예제 #2
0
        public JsonResult Create([FromForm] string token, [FromForm] string title, [FromForm] string coverImage,
                                 [FromForm] string describe, [FromForm] string tips, [FromForm] string caseStep, [FromForm] string caseTag)
        {
            DataResult dr = new DataResult();

            try
            {
                if (string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(describe) || string.IsNullOrWhiteSpace(coverImage))
                {
                    dr.code = "201";
                    dr.msg  = "参数错误";
                    return(Json(dr));
                }

                UserEntity userEntity = this.GetUserByToken(token);

                CaseBLL    caseBLL    = new CaseBLL();
                CaseEntity caseEntity = caseBLL.Create(userEntity.userId, title, coverImage, describe, tips);

                string msg = string.Empty;

                if (caseEntity != null)
                {
                    msg += "创建案例成功";

                    if (!string.IsNullOrWhiteSpace(caseStep))
                    {
                        List <CaseStepEntity> caseStepEntities = JsonConvert.DeserializeObject <List <CaseStepEntity> >(caseStep);

                        caseStepEntities = caseStepEntities.Where(it => !string.IsNullOrWhiteSpace(it.img) || !string.IsNullOrWhiteSpace(it.contents)).ToList();

                        caseStepEntities.ForEach(it =>
                        {
                            it.caseId   = caseEntity.caseId;
                            it.img      = it.img ?? "";
                            it.contents = it.contents ?? "";
                        });
                        if (caseStepEntities.Count > 0)
                        {
                            int rows = caseBLL.ActionDal.ActionDBAccess.Insertable(caseStepEntities).ExecuteCommand();
                            if (rows > 0)
                            {
                                msg += ",步骤添加成功";
                            }
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(caseTag))
                    {
                        int[] caseTags = JsonConvert.DeserializeObject <int[]>(caseTag);

                        if (caseTags.Length > 0)
                        {
                            List <CaseTagCorrelationEntity> caseTagCorrelationEntities = new List <CaseTagCorrelationEntity>();
                            for (int i = 0; i < caseTags.Length; i++)
                            {
                                caseTagCorrelationEntities.Add(new CaseTagCorrelationEntity
                                {
                                    caseId     = caseEntity.caseId,
                                    caseTagId  = caseTags[i],
                                    createDate = DateTime.Now,
                                    isDel      = false,
                                    modifyDate = DateTime.Now
                                });
                            }

                            int rows = caseBLL.ActionDal.ActionDBAccess.Insertable(caseTagCorrelationEntities).ExecuteCommand();

                            if (rows > 0)
                            {
                                msg += ",标签添加成功";
                            }
                        }
                    }
                }

                dr.code = "200";
                dr.msg  = msg;
            }
            catch (Exception ex)
            {
                dr.code = "999";
                dr.msg  = ex.Message;
            }

            return(Json(dr));
        }