public int Insert(IdeaDataObject idea) { int id = -1; using (var context = new IdeaPoolEntities()) { int ideastatusid = context.IdeaStatus .Where(x => x.Key == (idea.IsDraft ? IdeaStatusKeys.DRAFT : IdeaStatusKeys.SUBMITTED)) .Single().Id; Idea ideaData = new Idea { Title = idea.Title, HtmlContent = idea.DescriptionHtml, PlainContent = idea.Description, UniqueId = Guid.NewGuid(), UserId = idea.UserId, CreatedDate = DateTime.UtcNow, LastUpdated = DateTime.UtcNow, IdeaStatusId = ideastatusid, IsDraft = idea.IsDraft }; fieldOfwaterData.InsertIdeaFieldOfWater(context, ideaData, idea.FieldOfWater); fileData.Insert(context, idea.Files, ideaData); context.Ideas.Add(ideaData); context.SaveChanges(); id = ideaData.Id; } return(id); }
private void ImBtn_Click(object sender, EventArgs e) { if (FilePathTB.Text.Length > 0) { ImExcel excel = new ImExcel(); DataTable dt = excel.LoadExcel(FilePathTB.Text); List <ToolingDataSys.Code.Message> message = null; if (type == FileDataOperateType.Insert) { message = file.Insert(dt); } else if (type == FileDataOperateType.Update) { message = file.Update(dt); } else if (type == FileDataOperateType.Delete) { message = file.Delete(dt); } else if (type == FileDataOperateType.TransPosition) { IMoldFile moldFile = file as IMoldFile; message = moldFile.TransPosition(dt); } if (message != null && message.Count > 0) { new MessageDialog(message).ShowDialog(); } else { MessageBox.Show("导入成功!"); } } }
public int Insert(FileDataObject file, int ideaId, int userId) { if (!(ideaData.GetCreatorUserId(ideaId) == userId || userData.IsOwnerOrReviewer(userId))) { throw new PermissionException(); } file.Thumbnail = GetThumbnail(file); return(fileData.Insert(file, ideaId)); }