public ActionResult NewCheckType(CheckItemType model) { ControllerResult result = ControllerResult.SuccResult; string errorMsg = string.Empty; bool newResult = itemNameService.NewCheckItemType(model, out errorMsg); if (!newResult) { result = ControllerResult.FailResult; result.ErroMsg = errorMsg; } else { LogUserAction("进行了新建检测类别操作,检测类别编号为{0},检测类别名称{1}".Fmt(model.CheckItemCode, model.CheckItemName)); } return(Content(result.ToJson())); }
public bool NewCheckItemType(CheckItemType item, out string errorMsg) { errorMsg = string.Empty; bool Itemtypes = false; var itemtypes = GetAllTypeCodes(); foreach (var itemtype in itemtypes) { if (item.CheckItemCode.Contains(itemtype.CheckItemCode)) { errorMsg = "已有该类别编号!"; return(false); } else { Itemtypes = true; } } if (Itemtypes) { using (var db = dbFactory.Open()) { try { db.Insert(new CheckItemType { CheckItemCode = item.CheckItemCode, CheckItemName = item.CheckItemName }); cacheTypeCodes.Clear(); return(true); } catch (Exception ex) { errorMsg = ex.Message; return(false); } } } else { return(false); } }
protected override FrameworkElement FindParent(object sender, DependencyObject originalSource) { return(LayoutHelper.FindLayoutOrVisualParentObject(originalSource, x => CheckItemType(sender)(x), true, (DependencyObject)sender) as FrameworkElement); }
public string FormatCheckItems(CheckItemType citype) { string sss = ""; List<CheckItem> cis = goodStrings; if (citype == CheckItemType.ciBAD) cis = badStrings; for (int ii = 0; ii < cis.Count; ii++) { sss += (sss == "" ? "" : ", ") + cis[ii].checkString; if (cis[ii].numInstances > 1) sss += " (" + cis[ii].numInstances + ")"; } return sss; }
public JsonResult CreatePost([FromForm] PostCreateApi model) { using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { try { if (string.IsNullOrEmpty(model.Text)) { Result.Status = false; Result.Message = "You can not add a post without writing text ! "; return(BadResponse(Result)); } var appUser = _userService.FindByUserName(User.Identity.Name); if (appUser == null) { return(BadResponse(new ResultModel { Status = false, Message = "User not found !" })); } bool hasImage = CheckItemType.HasItemImage(model); bool hasVideo = CheckItemType.HasItemVideo(model); var imageUploadResult = new ImageUploadResult(); var videoUploadResult = new VideoUploadResult(); #region CloudinaryProcess #region ImageUploadingProcess if (hasImage) { using (var stream = model.Photo.OpenReadStream()) { var uploadParams = new ImageUploadParams { File = new FileDescription(model.Photo.Name, stream) }; imageUploadResult = _cloudinary.Upload(uploadParams); if (imageUploadResult.Error != null) { scope.Dispose(); return(BadResponse(ResultModel.Error("The upload process can not be done !"))); } } } #endregion #region VideoUploadingProcess if (hasVideo) { using (var stream = model.Video.OpenReadStream()) { var uploadParams = new VideoUploadParams { File = new FileDescription(model.Video.Name, stream) }; videoUploadResult = _cloudinary.Upload(uploadParams); if (videoUploadResult.Error != null) { scope.Dispose(); return(BadResponse(ResultModel.Error("The upload process can not be done !"))); } } } #endregion #endregion #region CRUD var newPost = new Post { Text = model.Text, PostType = hasImage == true ? (int)PostTypeEnum.PostImage : hasVideo == true ? (int)PostTypeEnum.PostVideo : (int)PostTypeEnum.PostText, CreatedBy = appUser.Id }; ResultModel postModel = _postService.Create(newPost); if (!postModel.Status) { scope.Dispose(); return(BadResponse(ResultModel.Error("The upload process can not be done !"))); } #region PostImages if (imageUploadResult != null && imageUploadResult.StatusCode == HttpStatusCode.OK) { var postImages = new PostImage { PostId = newPost.Id, ImageUrl = imageUploadResult.Url.ToString() }; ResultModel postImageModel = _postImageService.Create(postImages); if (!postImageModel.Status) { scope.Dispose(); return(BadResponse(ResultModel.Error("The upload process can not be done !"))); } } #endregion #region PostVideos if (videoUploadResult != null && videoUploadResult.StatusCode == HttpStatusCode.OK) { var postVideos = new PostVideo { PostId = newPost.Id, VideoUrl = videoUploadResult.Url.ToString() }; ResultModel postVideoModel = _postVideoService.Create(postVideos); if (!postVideoModel.Status) { scope.Dispose(); return(BadResponse(ResultModel.Error("The upload process can not be done !"))); } } #endregion #endregion scope.Complete(); //TODO //There must be an integration that returns the last post that has just been createad. return(OkResponse(new PostListDto { Id = newPost.Id, Text = newPost.Text, ImageUrl = imageUploadResult.Url?.ToString(), CreatedByUserName = appUser.UserName, CreatedByUserPhoto = appUser.UserDetail.ProfilePhotoPath, CreatedDate = newPost.CreatedDate, VideoUrl = videoUploadResult.Url?.ToString(), PostType = newPost.PostType, Comments = null })); } catch (Exception ex) { scope.Dispose(); Result.Status = false; Result.Message = ex.ToString(); return(BadResponse(Result)); } } }