public int SaveBillFile(BillFile file) { var entity = BillFiles .SingleOrDefault(x => x.BillId == file.BillId); if (entity == null) { entity = new Entities.BillFile(); DbContext.Add(entity); } entity.Data = file.Data; entity.Extension = file.Extension; entity.Name = file.Name; entity.BillId = file.BillId; entity.CreatedOn = file.CreatedOn; DbContext.SaveChanges(); return(file.Id ?? 0); }
public int UploadFile([FromRoute] int id) { var file = Request.Form.Files[0]; ; var fileName = Path.GetFileNameWithoutExtension(file.FileName); var extension = Path.GetExtension(file.FileName); var fileModel = new BillFile { BillId = id, CreatedOn = DateTime.UtcNow, FileType = file.ContentType, Extension = extension, Name = fileName }; using (var dataStream = new MemoryStream()) { file.CopyTo(dataStream); fileModel.Data = dataStream.ToArray(); } return(BillService.SaveBillFile(fileModel)); }
public int SaveBillFile(BillFile file) { return(FileRepository.SaveBillFile(file)); }