Пример #1
0
 private void detach_ResourceAttachments(ResourceAttachment entity)
 {
     this.SendPropertyChanging();
     entity.Resource = null;
 }
Пример #2
0
        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");
        }
Пример #3
0
 private void detach_ResourceAttachments(ResourceAttachment entity)
 {
     this.SendPropertyChanging();
     entity.Resource = null;
 }
Пример #4
0
        public ActionResult NewAttachment(int id)
        {
            var attachment = new ResourceAttachment
            {
                ResourceId = id
            };

            return View(attachment);
        }
Пример #5
0
        public ActionResult UploadAttachment(int id, ResourceAttachment attachment, HttpPostedFileBase file)
        {
            attachment.CreationDate = Util.Now;
            attachment.UpdateDate = Util.Now;
            attachment.FilePath = UploadAttachment(file);

            DbUtil.Db.ResourceAttachments.InsertOnSubmit(attachment);
            DbUtil.Db.SubmitChanges();

            return Redirect("/Resources/" + attachment.ResourceId);
        }
Пример #6
0
        public ActionResult SaveAttachment(int id, ResourceAttachment ra)
        {
            var attachment = DbUtil.Db.ResourceAttachments.FirstOrDefault(x => x.ResourceAttachmentId == id);

            attachment.Name = ra.Name;
            attachment.DisplayOrder = ra.DisplayOrder;

            DbUtil.Db.SubmitChanges();

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