public void AddOrUpdateDocument(ApplicationForm form, string name, string description, string contentType, int contentLength, string path) { var doc = Documents.FirstOrDefault(d => d.Form.Id == form.Id); if (doc != null) { doc.FileName = name; doc.Description = description; doc.ContentType = contentType; doc.ContentLength = contentLength; doc.Path = path; this.LastUpdated = DateTime.Now; } else { Documents.Add(new ApplicationDocument { Id = Guid.NewGuid(), FileName = name, Description = description, ContentType = contentType, ContentLength = contentLength, Path = path, CreateDate = DateTime.Now, Form = form }); this.LastUpdated = DateTime.Now; } }
public static ApplicationDocument NewDocument(Application app, ApplicationForm form, string name, string description, string contentType, int contentLength, string path) { return new ApplicationDocument() { Id = Guid.NewGuid(), FileName = name, Description = description, ContentType = contentType, ContentLength = contentLength, Path = path, CreateDate =DateTime.Now, Form = form, Application = app }; }
public async Task<ActionResult> Create(AppFormBindingModel form, HttpPostedFileBase file) { try { if (ModelState.IsValid) { var opp = await _uow.Opps.FindAsyncById(form.OpportunityId); var app = new ApplicationForm { Id = Guid.NewGuid(), Code = form.Code, Name = form.Name, Description = form.Description, Opportunity = opp }; //if (file != null) //{ // var saveFileName = Path.Combine(Server.MapPath("/documents/public/"), file.FileName); // file.SaveAs(saveFileName); // app.Path = saveFileName; // app.IsFolder = false; // app.ContentLength = file.ContentLength; // app.ContentType = MimeMapping.GetMimeMapping(file.FileName); //} _uow.AppForms.Add(app); await _uow.SaveAsync(); } return RedirectToAction<ApplicationFormController>(c => c.Index()).WithSuccess("Created"); } catch (Exception ex) { return RedirectToAction<ApplicationFormController>(c => c.Index()).WithError("Failed " + ex.Message); } }