private int SaveAttachedDocument(CreateIssue model, OperationStatus result, int fileCounter, HttpPostedFileBase file) { if (file != null) { fileCounter++; string fileName = Path.GetFileName(file.FileName).ToLower(); string fileKey = fileName; fileKey = fileKey.Replace(" ", "-").Replace("%", "-"); fileKey = String.Format("{0}-{1}-{2:n}-{3}", result.OperationID, fileCounter, Guid.NewGuid(), fileName); if (fileKey.Length > 99) fileKey = fileKey.Substring(0, 99); string path = Path.Combine(Server.MapPath("~/uploads"), fileKey); file.SaveAs(path); Document img = new Document { FileName = fileName, ParentID = model.Id }; img.FileAlias = fileKey; img.CreatedByID = UserID; img.ParentID = result.OperationID; var resultForImg = repo.SaveDocument(img); if (!resultForImg.Status) log.Debug(resultForImg); } return fileCounter; }
public OperationStatus SaveDocument(Document image) { image.CreatedDate = DateTime.UtcNow; db.Documents.Add(image); db.SaveChanges(); return new OperationStatus { Status = true }; }