public ActionResult Submit(int id, NewResourceModel m, IEnumerable<HttpPostedFileBase> files) { var resource = new Resource { CreationDate = Util.Now, Description = m.Description, MemberTypeIds = m.MemberTypeIds != null ? string.Join(",", m.MemberTypeIds) : string.Empty, DivisionId = m.DivisionId, CampusId = m.CampusId, Name = m.Name, DisplayOrder = m.DisplayOrder, ResourceTypeId = m.ResourceTypeId, ResourceCategoryId = m.ResourceCategoryId }; foreach (var orgId in m.OrganizationIds) { resource.ResourceOrganizations.Add(new ResourceOrganization { Resource = resource, OrganizationId = orgId }); } foreach (var orgTypeId in m.OrganizationTypeIds) { resource.ResourceOrganizationTypes.Add(new ResourceOrganizationType { Resource = resource, OrganizationTypeId = orgTypeId }); } if (resource.CampusId.HasValue && resource.CampusId < 1) resource.CampusId = null; if (resource.DivisionId.HasValue && resource.DivisionId < 1) resource.DivisionId = null; DbUtil.Db.Resources.InsertOnSubmit(resource); DbUtil.Db.SubmitChanges(); if (files != null && files.Any()) { foreach (var file in files) { if (file == null) continue; var attachment = new ResourceAttachment { ResourceId = resource.ResourceId, FilePath = UploadAttachment(file), Name = file.FileName, CreationDate = Util.Now }; DbUtil.Db.ResourceAttachments.InsertOnSubmit(attachment); DbUtil.Db.SubmitChanges(); } } return Redirect("/Resources"); }
public ActionResult Submit(int id, NewResourceModel m, IEnumerable <HttpPostedFileBase> files) { var resource = new Resource { CreationDate = Util.Now, Description = m.Description, MemberTypeIds = m.MemberTypeIds != null?string.Join(",", m.MemberTypeIds) : string.Empty, StatusFlagIds = m.StatusFlagIds != null?string.Join(",", m.StatusFlagIds) : string.Empty, DivisionId = m.DivisionId, CampusId = m.CampusId, Name = m.Name, DisplayOrder = m.DisplayOrder, ResourceTypeId = m.ResourceTypeId, ResourceCategoryId = m.ResourceCategoryId }; foreach (var orgId in m.OrganizationIds) { resource.ResourceOrganizations.Add(new ResourceOrganization { Resource = resource, OrganizationId = orgId }); } foreach (var orgTypeId in m.OrganizationTypeIds) { resource.ResourceOrganizationTypes.Add(new ResourceOrganizationType { Resource = resource, OrganizationTypeId = orgTypeId }); } if (resource.CampusId.HasValue && resource.CampusId < 1) { resource.CampusId = null; } if (resource.DivisionId.HasValue && resource.DivisionId < 1) { resource.DivisionId = null; } DbUtil.Db.Resources.InsertOnSubmit(resource); DbUtil.Db.SubmitChanges(); if (files != null && files.Any()) { foreach (var file in files) { if (file == null) { continue; } var attachment = new ResourceAttachment { ResourceId = resource.ResourceId, FilePath = UploadAttachment(file), Name = file.FileName, CreationDate = Util.Now }; DbUtil.Db.ResourceAttachments.InsertOnSubmit(attachment); DbUtil.Db.SubmitChanges(); } } return(Redirect("/Resources")); }