public PartialViewResult Edit(ProjectAttachmentPrimaryKey projectAttachmentPrimaryKey)
        {
            var projectAttachment = projectAttachmentPrimaryKey.EntityObject;
            var viewModel         = new EditProjectAttachmentsViewModel(projectAttachment);

            return(ViewEdit(viewModel));
        }
        public PartialViewResult Delete(ProjectAttachmentPrimaryKey projectAttachmentPrimaryKey)
        {
            var projectAttachment = projectAttachmentPrimaryKey.EntityObject;
            var viewModel         = new ConfirmDialogFormViewModel(projectAttachment.ProjectAttachmentID);

            return(ViewDelete(projectAttachment, viewModel));
        }
        public ActionResult Edit(ProjectAttachmentPrimaryKey projectAttachmentPrimaryKey, EditProjectAttachmentsViewModel viewModel)
        {
            var projectAttachment = projectAttachmentPrimaryKey.EntityObject;

            if (!ModelState.IsValid)
            {
                return(ViewEdit(viewModel));
            }

            viewModel.UpdateModel(projectAttachment);

            SetMessageForDisplay($"Successfully update document \"{projectAttachment.DisplayName}\".");

            return(new ModalDialogFormJsonResult());
        }
        public ActionResult Delete(ProjectAttachmentPrimaryKey projectAttachmentPrimaryKey,
                                   ConfirmDialogFormViewModel viewModel)
        {
            var projectAttachment = projectAttachmentPrimaryKey.EntityObject;
            var displayName       = projectAttachment.DisplayName;

            if (!ModelState.IsValid)
            {
                return(ViewDelete(projectAttachment, viewModel));
            }

            projectAttachment.Attachment.DeleteFull(HttpRequestStorage.DatabaseEntities);

            SetMessageForDisplay($"Successfully deleted document \"{displayName}\".");

            return(new ModalDialogFormJsonResult());
        }
Example #5
0
        public virtual IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var validationResults = new List <ValidationResult>();

            ProjectAttachmentPrimaryKey projectAttachmentPrimaryKey = AttachmentID;
            var projectAttachment = projectAttachmentPrimaryKey.EntityObject;

            // We want to validate that the DisplayName is unique per project & attachment type. A project can have duplicate display names as long as they are different attachment types
            if (HttpRequestStorage.DatabaseEntities.ProjectAttachments.Where(x => x.ProjectID == ParentID && x.ProjectAttachmentID != AttachmentID && x.AttachmentTypeID == projectAttachment.AttachmentTypeID)
                .Any(x => x.DisplayName.ToLower() == DisplayName.ToLower()))
            {
                AttachmentTypePrimaryKey attachmentTypePrimaryKey = projectAttachment.AttachmentTypeID;
                var attachmentType = attachmentTypePrimaryKey.EntityObject;

                validationResults.Add(new SitkaValidationResult <NewProjectAttachmentViewModel, string>($"There is already an attachment with the display name \"{DisplayName}\" under the {attachmentType.AttachmentTypeName} attachment type for this {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()}.", m => m.DisplayName));
            }

            return(validationResults);
        }