public ActionResult AddPost(UpdatePostViewModel model) { if (!ModelState.IsValid) { return(PartialView(model)); } var image = model.Image; byte[] fileBytes = { }; if (model.Image != null) { using (var ms = new MemoryStream()) { image.CopyTo(ms); fileBytes = ms.ToArray(); } } var isPostCreated = _historyRepository.AddPost(new PostViewModel { Title = model.Title, Content = model.Content, PostDate = model.PostDate, TimePeriodId = model.SelectedPeriodId, EventTypes = model.SelectedEventTypes, FigureTypes = model.SelectedFigureTypes, Image = Convert.ToBase64String(fileBytes), }); return(Json(new { success = isPostCreated })); }
public bool AddPost(PostViewModel postViewModel) { try { return(_repository.AddPost(postViewModel)); } catch (Exception) { return(false); } }