public async Task <IActionResult> Create(DocumentViewModel documentViewModel) { if (ModelState.IsValid) { var document = new Document(); var project = _context.Projects.Include(p => p.Documents).FirstOrDefault(p => p.ProjectId == documentViewModel.ProjectId); var file = new DocumentFile(); file.Name = documentViewModel.Name; file.ModifiedTime = DateTime.Now; using (var memoryStream = new MemoryStream()) { await documentViewModel.Data.CopyToAsync(memoryStream); file.Data = memoryStream.ToArray(); } _context.Add(file); document.File = file; project.Documents.Add(document); _context.Add(document); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(documentViewModel)); }
public async Task <IActionResult> Create([Bind("OrganizationId,Name")] Organization organization) { if (ModelState.IsValid) { _context.Add(organization); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(organization)); }
public async Task <IActionResult> Create(ProjectProperty projectProperty) { if (ModelState.IsValid) { projectProperty.OwnerProject = _context.Projects.Find(projectProperty.OwnerProject.ProjectId); _context.Add(projectProperty); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(projectProperty)); }
public async Task <IActionResult> Create(DepartmentProperty departmentProperty) { if (ModelState.IsValid) { departmentProperty.OwnerDepartment = _context.Departments.Find(departmentProperty.OwnerDepartment.DepartmentId); _context.Add(departmentProperty); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(departmentProperty)); }
public async Task <IActionResult> Create(OrganizationProperty model) { if (ModelState.IsValid) { model.OwnerOrganization = _context.Organizations.Find(model.OwnerOrganization.OrganizationId); _context.Add(model); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public async Task <IActionResult> Create(Department department) { if (ModelState.IsValid) { department.OwnerOrganization = _context.Organizations.Find(department.OwnerOrganization.OrganizationId); _context.Add(department); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(department)); }