Exemplo n.º 1
0
        public ActionResult Edit(int id)
        {
            var resource = new EditResourceModel(DbUtil.Db.Resources.FirstOrDefault(x => x.ResourceId == id));

            return View(resource);
        }
Exemplo n.º 2
0
        public ActionResult Save(int id, EditResourceModel model)
        {
            var resource = DbUtil.Db.Resources.FirstOrDefault(x => x.ResourceId == id);

            if (model.DivisionId.HasValue && model.DivisionId < 1)
                model.DivisionId = null;
            if (model.CampusId.HasValue && model.CampusId < 1)
                model.CampusId = null;

            resource.Name = model.Name;
            resource.DisplayOrder = model.DisplayOrder;
            resource.DivisionId = model.DivisionId;
            resource.CampusId = model.CampusId;
            resource.MemberTypeIds = model.MemberTypeIds != null ? string.Join(",", model.MemberTypeIds) : string.Empty;
            resource.Description = model.Description;
            resource.ResourceTypeId = model.ResourceTypeId;
            resource.ResourceCategoryId = model.ResourceCategoryId;

            DbUtil.Db.ResourceOrganizations.DeleteAllOnSubmit(
                DbUtil.Db.ResourceOrganizations.Where(ro => ro.ResourceId == resource.ResourceId)
                );
            foreach (var orgId in model.OrganizationIds)
            {
                resource.ResourceOrganizations.Add(new ResourceOrganization
                {
                    Resource = resource,
                    OrganizationId = orgId
                });
            }

            DbUtil.Db.ResourceOrganizationTypes.DeleteAllOnSubmit(
                DbUtil.Db.ResourceOrganizationTypes.Where(ro => ro.ResourceId == resource.ResourceId)
                );
            foreach (var orgTypeId in model.OrganizationTypeIds)
            {
                resource.ResourceOrganizationTypes.Add(new ResourceOrganizationType
                {
                    Resource = resource,
                    OrganizationTypeId = orgTypeId
                });
            }

            DbUtil.Db.SubmitChanges();

            return Redirect("/Resources/" + resource.ResourceId + "/");
        }