public ServiceResult CreatePostFile(PostFileCreateDto model) { var serviceResult = new ServiceResult(true); #region validation if (string.IsNullOrEmpty(model.Title)) { serviceResult.AddError("عنوان نمی تواند فاید مقدار باشد"); } if (!string.IsNullOrEmpty(model.Title) && model.Title.Length > 128) { serviceResult.AddError("عنوان نمی تواند بیش از 128 کاراکتر را شامل شود".ToPersianNumbers()); } #endregion if (serviceResult.IsSuccess) { var entity = model.ToEntity(); _context.Entry(entity).State = EntityState.Added; if (_context.SaveChanges() == 0) { serviceResult.AddError("در انجام عملیات خطایی رخ داد"); } } return(serviceResult); }
public static PostFile ToEntity(this PostFileCreateDto source) { return(new PostFile { PostId = source.PostId, CountDownload = 0, FileName = source.FileName, Length = source.Length, Title = source.Title, Type = source.FileType }); }