public VocalBase VocalAddNew(VocalAdd newItem) { var addedItem = ds.VocalClass.Add(mapper.Map <VocalClass>(newItem)); // Doc if (newItem.TextUpload != null) { var textSize = newItem.TextUpload.ContentLength; byte[] textBytes = new byte[textSize]; newItem.TextUpload.InputStream.Read(textBytes, 0, textSize); addedItem.TextContentType = newItem.TextUpload.ContentType; addedItem.Text = textBytes; addedItem.txtB = true; } // Photo if (newItem.PhotoUpload != null) { var photoSize = newItem.PhotoUpload.ContentLength; byte[] photoBytes = new byte[photoSize]; newItem.PhotoUpload.InputStream.Read(photoBytes, 0, photoSize); addedItem.Photo = photoBytes; addedItem.PhotoContentType = newItem.PhotoUpload.ContentType; addedItem.imageB = true; } // Audio if (newItem.AudioUpload != null) { var audioSize = newItem.AudioUpload.ContentLength; byte[] audioBytes = new byte[audioSize]; newItem.AudioUpload.InputStream.Read(audioBytes, 0, audioSize); addedItem.Audio = audioBytes; addedItem.AudioContentType = newItem.AudioUpload.ContentType; addedItem.audioB = true; } // Video if (newItem.VideoUpload != null) { var videoSize = newItem.VideoUpload.ContentLength; byte[] videoBytes = new byte[videoSize]; newItem.VideoUpload.InputStream.Read(videoBytes, 0, videoSize); addedItem.Video = videoBytes; addedItem.VideoContentType = newItem.VideoUpload.ContentType; addedItem.videoB = true; } ds.SaveChanges(); var var1 = addedItem; return((addedItem == null) ? null : mapper.Map <VocalBase>(addedItem)); }
public ActionResult Create(VocalAdd newItem) { if (!ModelState.IsValid) { return(RedirectToAction("index")); } var addedItem = m.VocalAddNew(newItem); if (addedItem == null) { return(View(newItem)); } else { return(RedirectToAction("details", new { id = addedItem.Id })); } }