public void SaveUpload(int id, UploadDTO file) { var currentProject = _projectRepo.Get(id).FirstOrDefault(); // check if current project is null first if (currentProject != null) { var newUpload = new Upload() { Name = file.Name, Url = file.Url, Project = currentProject, Type = (Upload.Classification)Enum.Parse(typeof(Upload.Classification), file.Type) }; _uploadRepo.Add(newUpload); _uploadRepo.SaveChanges(); } }
public async Task<IHttpActionResult> Post(int id) { var formData = await this.ReadFile(); var file = formData.Files[0]; var dst = HttpContext.Current.Server.MapPath("~/Public/" + file.RemoteFileName); file.FileInfo.MoveTo(dst); var type = formData.FormData["type"][0]; var dto = new UploadDTO() { Name = file.RemoteFileName, Url = Url.Content("~/Public/" + file.RemoteFileName), Type = type }; _uploadServ.SaveUpload(id, dto); return Ok(); }