public async Task <IActionResult> Add(IFormCollection model) { int index = await _cmsRepo.GetIndex(Guid.Parse(model["ModelId"].ToString())); foreach (var file in model.Files) { var filename = FileHelper.ProcessFileUpload(file, _webHostEnv); var content = new Content() { Id = Guid.NewGuid(), ModelId = Guid.Parse(model["ModelId"].ToString()), FieldId = Guid.Parse(file.Name.ToString()), Contents = filename, Index = index + 1 }; _dataRepository.Add(content); } foreach (var item in model.Keys) { if (item != "__RequestVerificationToken" && item != "ModelId") { var content = new Content() { Id = Guid.NewGuid(), ModelId = Guid.Parse(model["ModelId"].ToString()), FieldId = Guid.Parse(item.ToString()), Contents = model[item].ToString(), Index = index + 1 }; _dataRepository.Add(content); } } if (await _dataRepository.SaveAll()) { return(RedirectToAction("Index", "Fields", new { id = model["ModelId"] })); } else { return(View(model)); } }