public bool CreateTeamMessaging(TeamMessagingCreate model) { byte[] bytes = null; if (model.File != null) { Stream fs = model.File.InputStream; BinaryReader br = new BinaryReader(fs); bytes = br.ReadBytes((Int32)fs.Length); } var entity = new TeamMessaging() { FileContent = bytes, UserID = _userID, Title = model.Title, Content = model.Content, CreatedUtc = DateTimeOffset.Now, TeamID = model.TeamID, }; using (var ctx = new ApplicationDbContext()) { ctx.TeamMessaging.Add(entity); return(ctx.SaveChanges() == 1); } }
public IHttpActionResult Post(TeamMessagingCreate teamMessagingCreate) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateTeamMessagingService(); if (!service.CreateTeamMessaging(teamMessagingCreate)) { return(InternalServerError()); } return(Ok()); }