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 EditResourceModel(Resource r) { ResourceId = r.ResourceId; ResourceTypeId = r.ResourceTypeId; ResourceCategoryId = r.ResourceCategoryId; Name = r.Name; DivisionId = r.DivisionId; OrganizationIds = r.ResourceOrganizations.Select(x => x.OrganizationId); OrganizationTypeIds = r.ResourceOrganizationTypes.Select(x => x.OrganizationTypeId); CampusId = r.CampusId; MemberTypeIds = string.IsNullOrWhiteSpace(r.MemberTypeIds) ? new List<int>() : r.MemberTypeIds.Split(',').Select(int.Parse).ToList(); Description = r.Description; DisplayOrder = r.DisplayOrder ?? 0; }
private void detach_Resources(Resource entity) { this.SendPropertyChanging(); entity.ResourceType = null; }
private void attach_Resources(Resource entity) { this.SendPropertyChanging(); entity.ResourceType = this; }
private void attach_Resources(Resource entity) { this.SendPropertyChanging(); entity.Division = this; }
public ResourceModel(Resource resource) { Resource = resource; ResourceId = resource.ResourceId; Attachments = DbUtil.Db.ResourceAttachments.Where(x => x.ResourceId == ResourceId).ToList(); }
private void detach_Resources(Resource entity) { this.SendPropertyChanging(); entity.Organization = null; }
private void detach_Resources(Resource entity) { this.SendPropertyChanging(); entity.Campu = null; }
private void attach_Resources(Resource entity) { this.SendPropertyChanging(); entity.Campu = this; }