private ActionResult Save(ProjectAttachment viewModel)
        {
            if (ModelState.IsValid)
            {
                // remove the path only get the file name
                viewModel.Url = Path.GetFileName(viewModel.Url);

                // save the attachment only applicable for uploading a new file (attachment is not ammendable) !!!
                byte[] attachmentInBytes = null;
                if (viewModel.Attachment != null && viewModel.Attachment.ContentLength > 0 && viewModel.Attachment.InputStream != null)
                {
                    attachmentInBytes = viewModel.Attachment.InputStream.ToByteArray();

                    // overwrite the url with the file name only (exclude the path)
                    viewModel.Url = Path.GetFileName(viewModel.Attachment.FileName);
                }

                viewModel.CreatedBy = User.Identity.Name.RemoveDomain();
                viewModel.UpdatedBy = User.Identity.Name.RemoveDomain();
                PatService.SaveAttachment(viewModel, attachmentInBytes);
                TempData[CommonConstants.FlashMessageTypeInfo] = string.Format(@"Attachment uploaded/ saved successfully: {0} - {1}.", viewModel.Id, viewModel.DocumentName);
                return(RedirectToProjectDetailsPageTab(viewModel.ProjectId, CommonConstants.ProjectTab_Documents));
            }
            return(View("Edit", viewModel));
        }
Exemple #2
0
        /// <summary>
        /// Gets Project attachment  by identifier.
        /// </summary>
        /// <param name="id">The project attachment Id.</param>
        /// <returns></returns>
        public ProjectAttachment GetById(int id)
        {
            ProjectAttachment projectAttachment = null;
            var projectAttachmentList           = new List <ProjectAttachment>();

            using (var connection = new SqlConnection(DbConnection))
            {
                using (var command = new SqlCommand("PaProjectAttachementGet", connection))
                {
                    var sqlParams = new List <SqlParameter>();

                    var paramReturnValue = new SqlParameter("@return_value", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.ReturnValue
                    };
                    sqlParams.Add(paramReturnValue);

                    SqlHelper.AddIntPara(id, "@Id", sqlParams);

                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(sqlParams.ToArray());
                    connection.Open();

                    LoadProjectAttachmentList(projectAttachmentList, command);

                    if (projectAttachmentList.Count > 0)
                    {
                        projectAttachment = projectAttachmentList[0];
                    }
                }
            }
            return(projectAttachment);// as T;
        }
        // 添加
        public ResultEntity <int> InsertProjectAttachment(ProjectAttachment uie)
        {
            ResultEntity <int> result;

            try
            {
                int IntRet    = 0;
                var repResult = dal.Insert <ProjectAttachment>(uie);
                if (repResult != null)
                {
                    IntRet = int.Parse(repResult.ToString());
                }
                if (IntRet > 0)
                {
                    result = new ResultEntity <int>(true, ConstantDefine.TipSaveSuccess, IntRet);
                }
                else
                {
                    result = new ResultEntity <int>(ConstantDefine.TipSaveFail);
                }
            }
            catch (Exception ex)
            {
                Loger.LogErr(ex);
                result = new ResultEntity <int>(ex.Message);
            }
            return(result);
        }
        public async Task <IActionResult> Create([Bind("Id,FormFile,Image,Description,Created,FileName,FileData,ProjectId,CustomUserId")] ProjectAttachment projectAttachment)
        {
            if (!(await _roleService.IsUserInRoleAsync(await _userManager.GetUserAsync(User), Roles.DemoUser.ToString())))
            {
                if (ModelState.IsValid)
                {
                    MemoryStream ms = new MemoryStream();
                    await projectAttachment.FormFile.CopyToAsync(ms);

                    projectAttachment.FileData    = ms.ToArray();
                    projectAttachment.FileName    = projectAttachment.FormFile.FileName;
                    projectAttachment.ContentType = projectAttachment.FormFile.ContentType;

                    projectAttachment.Created      = DateTimeOffset.Now;
                    projectAttachment.CustomUserId = _userManager.GetUserId(User);
                    var id = projectAttachment.ProjectId;
                    _context.Add(projectAttachment);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Details", "Projects", new { id }));
                }
                ViewData["CustomUserId"] = new SelectList(_context.Users, "Id", "Id", projectAttachment.CustomUserId);
                ViewData["ProjectId"]    = new SelectList(_context.Project, "Id", "Id", projectAttachment.ProjectId);
                var projectId = projectAttachment.ProjectId;
                return(RedirectToAction("Details", "Projects", new { projectId }));
            }
            return(RedirectToAction("DemoUser", "Projects"));
        }
        // 修改
        public ResultEntity <int> UpdateProjectAttachment(ProjectAttachment uie)
        {
            ResultEntity <int> result;

            try
            {
                int IntRet    = 0;
                var repResult = dal.Update <ProjectAttachment>(uie);

                if (repResult)
                {
                    IntRet = 1;
                }

                if (IntRet > 0)
                {
                    result = new ResultEntity <int>(true, ConstantDefine.TipSaveSuccess, IntRet);
                }
                else
                {
                    result = new ResultEntity <int>(ConstantDefine.TipSaveFail);
                }
            }
            catch (Exception ex)
            {
                Loger.LogErr(ex);
                result = new ResultEntity <int>(ex.Message);
            }
            return(result);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Description,Created,FileName,FileData,ProjectId,CustomUserId")] ProjectAttachment projectAttachment)
        {
            if (!(await _roleService.IsUserInRoleAsync(await _userManager.GetUserAsync(User), Roles.DemoUser.ToString())))
            {
                if (id != projectAttachment.Id)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(projectAttachment);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!ProjectAttachmentExists(projectAttachment.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["CustomUserId"] = new SelectList(_context.Users, "Id", "Id", projectAttachment.CustomUserId);
                ViewData["ProjectId"]    = new SelectList(_context.Project, "Id", "Id", projectAttachment.ProjectId);
                return(View(projectAttachment));
            }
            return(RedirectToAction("DemoUser", "Projects"));
        }
        private ProjectAttachment AttachmentGet(Project project, PmActivity activity, long idItem)
        {
            ProjectAttachment attachment = null;

            try
            {
                if (activity != null)
                {
                    attachment = (from a in Manager.GetIQ <ProjectAttachment>()
                                  where a.Item != null && a.Project != null && a.Project.Id == project.Id &&
                                  a.Activity != null && a.Activity.Id == activity.Id &&
                                  a.Item != null && a.Item.Id == idItem
                                  select a).Skip(0).Take(1).ToList().FirstOrDefault();
                }
                else
                {
                    attachment = (from a in Manager.GetIQ <ProjectAttachment>()
                                  where a.Item != null && a.Project != null && a.Project.Id == project.Id && a.Item.Id == idItem
                                  select a).Skip(0).Take(1).ToList().FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
            }

            return(attachment);
        }
        public async Task <IActionResult> PutProjectAttachments([FromRoute] int id, [FromBody] ProjectAttachment projectAttachments)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != projectAttachments.ProjAttId)
            {
                return(BadRequest());
            }

            _context.Entry(projectAttachments).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProjectAttachmentsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public ActionResult Edit(ProjectAttachment projectAttachment, HttpPostedFileBase fileupload)
        {
            if (ModelState.IsValid)
            {
                #region Upload and resize image if needed
                if (fileupload != null)
                {
                    string filename    = Path.GetFileName(fileupload.FileName);
                    string newFilename = Guid.NewGuid().ToString().Replace("-", string.Empty)
                                         + Path.GetExtension(filename);

                    string newFilenameUrl   = "/Uploads/ProjectAttachments/" + newFilename;
                    string physicalFilename = Server.MapPath(newFilenameUrl);
                    fileupload.SaveAs(physicalFilename);
                    projectAttachment.FileUrl = newFilenameUrl;
                }
                #endregion
                projectAttachment.IsDeleted       = false;
                db.Entry(projectAttachment).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", new { id = projectAttachment.ProjectId }));
            }
            ViewBag.ProjectId = projectAttachment.ProjectId;
            return(View(projectAttachment));
        }
        private ProjectAttachment AttachmentGet(ModuleLink link)
        {
            ProjectAttachment attachment = (from a in Manager.GetIQ <ProjectAttachment>()
                                            where a.Link != null && link.Id == a.Link.Id select a).Skip(0).Take(1).ToList().FirstOrDefault();

            return(attachment);
        }
        public bool AllowActionExecution(ModuleLink link, int idUser, int idCommunity, int idRole, Dictionary <string, long> moduleUserLong = null, Dictionary <string, string> moduleUserString = null)
        {
            litePerson person = Manager.Get <litePerson>(idUser);

            switch (link.SourceItem.ObjectTypeID)
            {
            case (Int32)ModuleProjectManagement.ObjectType.Project:
            case (Int32)ModuleProjectManagement.ObjectType.Task:
                switch (link.DestinationItem.ServiceCode)
                {
                case  lm.Comol.Core.FileRepository.Domain.ModuleRepository.UniqueCode:
                    ProjectAttachment attachment = AttachmentGet(link);
                    if (attachment != null && attachment.Project != null && attachment.Link != null && link.DestinationItem.ObjectLongID == attachment.Item.Id && link.DestinationItem.FQN == attachment.Item.GetType().FullName)
                    {
                        dtoAttachmentPermission permissions = AttachmentGetPermissions(person, attachment, attachment.Project, attachment.Activity);
                        return(permissions.Play || permissions.Download);
                    }
                    break;

                default:
                    return(false);
                }
                break;

            default:
                return(false);
            }
            return(false);
        }
Exemple #12
0
        /// <summary>
        /// Updates the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        public void Update(ProjectAttachment entity)
        {
            var projectAttachment = entity;

            using (var connection = new SqlConnection(DbConnection))
            {
                using (var command = new SqlCommand("PaProjectAttachementUpdate", connection))
                {
                    var sqlParams = new List <SqlParameter>();

                    SqlHelper.AddReturnPara("@return_value", sqlParams);

                    SqlHelper.AddIntPara(projectAttachment.Id, "@Id", sqlParams);
                    SqlHelper.AddIntPara(projectAttachment.ProjectId, "@ProjectId", sqlParams);
                    SqlHelper.AddVarcharPara(projectAttachment.DocumentName, "@DocumentName", sqlParams);
                    SqlHelper.AddVarcharPara(projectAttachment.Description, "@Description", sqlParams);
                    SqlHelper.AddVarcharPara(projectAttachment.Url, "@Url", sqlParams);
                    SqlHelper.AddVarcharPara(projectAttachment.UpdatedBy, "@UpdatedBy", sqlParams);
                    SqlHelper.AddDatePara(DateTime.Now, "@UpdatedOn", sqlParams);

                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(sqlParams.ToArray());

                    connection.Open();

                    command.ExecuteNonQuery();
                }
            }
        }
        public ActionResult SaveProjectAttachment(ProjectAttachment entity)
        {
            ResponseEntity <int> response;

            if (entity.Id == 0)
            {
                entity.IsDelete   = 0;
                entity.CreateBy   = "";
                entity.CreateTime = DateTime.Now;
                entity.UpdateBy   = "";
                entity.UpdateTime = DateTime.Now;
                var result = new ProjectAttachmentBLL().InsertProjectAttachment(entity);

                response = new ResponseEntity <int>(result.Success, result.Message, result.Data);

                new LogBLL().LogEvent(CurrenUserInfo.LoginName, GDS.Entity.Constant.ConstantDefine.ModuleProject,
                                      GDS.Entity.Constant.ConstantDefine.TypeUpdate, GDS.Entity.Constant.ConstantDefine.ActionUpload, $"{result.Data}");
            }
            else
            {
                entity.UpdateBy   = "";
                entity.UpdateTime = DateTime.Now;
                var result = new ProjectAttachmentBLL().UpdateProjectAttachment(entity);

                response = new ResponseEntity <int>(result.Success, result.Message, result.Data);

                new LogBLL().LogEvent(CurrenUserInfo.LoginName, GDS.Entity.Constant.ConstantDefine.ModuleProject,
                                      GDS.Entity.Constant.ConstantDefine.TypeUpdate, GDS.Entity.Constant.ConstantDefine.ActionUpload, $"{entity.Id}");
            }

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
        public ActionResult DeleteConfirmed(Guid id)
        {
            ProjectAttachment projectAttachment = db.ProjectAttachments.Find(id);

            projectAttachment.IsDeleted    = true;
            projectAttachment.DeletionDate = DateTime.Now;

            db.SaveChanges();
            return(RedirectToAction("Index", new { id = projectAttachment.ProjectId }));
        }
        public async Task <IActionResult> PostProjectAttachments([FromBody] ProjectAttachment projectAttachments)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.ProjectAttachments.Add(projectAttachments);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetProjectAttachments", new { id = projectAttachments.ProjAttId }, projectAttachments));
        }
Exemple #16
0
        /// <summary>
        /// Inserts the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="fileData">The file data.</param>
        /// <exception cref="System.ArgumentNullException">fileData</exception>
        public void Insert(ProjectAttachment entity, byte[] fileData)
        {
            if (fileData == null)
            {
                throw new ArgumentNullException("fileData");
            }

            using (var connection = new SqlConnection(DbConnection))
            {
                using (var command = new SqlCommand("PaProjectAttachementInsert", connection))
                {
                    var sqlParams = new List <SqlParameter>();

                    var paramReturnValue = new SqlParameter("@return_value", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.ReturnValue
                    };
                    sqlParams.Add(paramReturnValue);

                    var documentId = new SqlParameter("@Id", SqlDbType.Int)
                    {
                        Direction = ParameterDirection.InputOutput,
                        Value     = 0
                    };

                    sqlParams.Add(documentId);

                    SqlHelper.AddIntPara(entity.ProjectId, "@ProjectId", sqlParams);
                    SqlHelper.AddVarcharPara(entity.DocumentName, "@DocumentName", sqlParams);
                    SqlHelper.AddVarcharPara(entity.Description, "@Description", sqlParams);
                    SqlHelper.AddVarcharPara(entity.Url, "@Url", sqlParams);
                    SqlHelper.AddVarbinaryPara(fileData, "@Attachment", sqlParams);
                    SqlHelper.AddVarcharPara(entity.CreatedBy, "@CreatedBy", sqlParams);
                    SqlHelper.AddDatePara(DateTime.Now, "@CreatedOn", sqlParams);
                    SqlHelper.AddVarcharPara(entity.UpdatedBy, "@UpdatedBy", sqlParams);
                    SqlHelper.AddDatePara(DateTime.Now, "@UpdatedOn", sqlParams);

                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(sqlParams.ToArray());

                    connection.Open();

                    command.ExecuteNonQuery();

                    if (((Int32)command.Parameters["@return_value"].Value) != 0)
                    {
                        return;
                    }

                    entity.Id = (int)documentId.Value;
                }
            }
        }
        private dtoAttachmentPermission AttachmentGetPermissions(litePerson person, ProjectAttachment attachment, Project project, PmActivity activity)
        {
            dtoAttachmentPermission result = new dtoAttachmentPermission();

            if (attachment != null && project != null)
            {
                lm.Comol.Core.FileRepository.Domain.ModuleRepository repositoryPermissions = GetRepositoryPermissions((project.isPortal) ? 0 : (project.Community == null) ? -1 : project.Community.Id, person.Id);
                ModuleProjectManagement mPermission     = (project.isPortal) ? ModuleProjectManagement.CreatePortalmodule((person == null) ? (Int32)UserTypeStandard.Guest : person.TypeID) : new ModuleProjectManagement(Manager.GetModulePermission(person.Id, (!project.isPortal && project.Community != null) ? project.Community.Id : 0, GetIdModule()));
                ProjectResource         resource        = project.Resources.Where(r => r.Deleted == BaseStatusDeleted.None && r.Type == ResourceType.Internal && r.Person == person).FirstOrDefault();
                PmActivityPermission    rolePermissions = GetRolePermissions(AttachmentGetContainerRole(project, activity, resource, mPermission));

                switch (attachment.Type)
                {
                case AttachmentType.file:
                    result.Download = (attachment.Item != null && attachment.Item.IsDownloadable || attachment.Item.Type == ItemType.Link) && (HasPermission(rolePermissions, PmActivityPermission.ViewAttachments) || HasPermission(rolePermissions, PmActivityPermission.DownloadAttacchments));
                    result.Play     = (attachment.Item != null && (attachment.Item.Type == ItemType.Multimedia || attachment.Item.Type == ItemType.ScormPackage || attachment.Item.Type == ItemType.VideoStreaming)) && (HasPermission(rolePermissions, PmActivityPermission.ViewAttachments) || HasPermission(rolePermissions, PmActivityPermission.DownloadAttacchments));

                    switch (attachment.Item.Type)
                    {
                    case ItemType.ScormPackage:
                    case ItemType.Multimedia:
                        result.ViewMyStatistics = HasPermission(rolePermissions, PmActivityPermission.ViewAttachments);
                        if (attachment.Item.IsInternal || (repositoryPermissions.Administration || (repositoryPermissions.EditOthersFiles || (repositoryPermissions.EditMyFiles && attachment.Item.IdOwner == person.Id))))
                        {
                            result.ViewOtherStatistics = HasPermission(rolePermissions, PmActivityPermission.ManageAttachments) || (HasPermission(rolePermissions, PmActivityPermission.ManageActivityAttachments) && attachment.IdCreatedBy == person.Id);
                            result.SetMetadata         = result.ViewOtherStatistics;
                        }
                        break;

                    case ItemType.Link:
                        result.Play = result.Download;
                        break;
                    }
                    result.Edit = false;
                    break;

                case AttachmentType.url:
                    result.Download = HasPermission(rolePermissions, PmActivityPermission.ViewAttachments) || HasPermission(rolePermissions, PmActivityPermission.DownloadAttacchments);
                    result.Play     = result.Download;
                    result.Edit     = HasPermission(rolePermissions, PmActivityPermission.ManageAttachments) || (HasPermission(rolePermissions, PmActivityPermission.ManageActivityAttachments) && attachment.IdCreatedBy == person.Id);
                    break;
                }

                result.Delete        = false;
                result.UnDelete      = (attachment.Deleted != BaseStatusDeleted.None) && (HasPermission(rolePermissions, PmActivityPermission.VirtualUnDeleteAttachments) || (HasPermission(rolePermissions, PmActivityPermission.ManageActivityAttachments) && attachment.IdCreatedBy == person.Id));
                result.Unlink        = (attachment.SharedItems.Any() && activity != null && attachment.SharedItems.Where(s => s.Deleted == BaseStatusDeleted.None && s.Activity != null && s.Activity.Id == activity.Id && s.Type == AttachmentLinkType.Shared).Any() && attachment.Deleted == BaseStatusDeleted.None) && (HasPermission(rolePermissions, PmActivityPermission.VirtualDeleteAttachments) || HasPermission(rolePermissions, PmActivityPermission.ManageAttachments) || (HasPermission(rolePermissions, PmActivityPermission.ManageActivityAttachments) && attachment.IdCreatedBy == person.Id));
                result.VirtualDelete = (attachment.Deleted == BaseStatusDeleted.None) && (HasPermission(rolePermissions, PmActivityPermission.VirtualDeleteAttachments) || HasPermission(rolePermissions, PmActivityPermission.ManageAttachments) || (HasPermission(rolePermissions, PmActivityPermission.ManageActivityAttachments) && attachment.IdCreatedBy == person.Id));
            }

            return(result);
        }
        public ActionResult Delete(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProjectAttachment projectAttachment = db.ProjectAttachments.Find(id);

            if (projectAttachment == null)
            {
                return(HttpNotFound());
            }
            return(View(projectAttachment));
        }
Exemple #19
0
        public ActionResult Create(Project project, List <HttpPostedFileBase> attachments)
        {
            if (ModelState.IsValid)
            {
                project.IsDeleted    = false;
                project.CreationDate = DateTime.Now;
                project.Id           = Guid.NewGuid();
                db.Projects.Add(project);

                #region Upload and resize image if needed

                if (attachments != null)
                {
                    foreach (HttpPostedFileBase t in attachments)
                    {
                        if (t != null)
                        {
                            string filename    = Path.GetFileName(t.FileName);
                            string newFilename = Guid.NewGuid().ToString().Replace("-", string.Empty)
                                                 + Path.GetExtension(filename);

                            string newFilenameUrl   = "/Uploads/ProjectAttachments/" + newFilename;
                            string physicalFilename = Server.MapPath(newFilenameUrl);

                            t.SaveAs(physicalFilename);

                            ProjectAttachment projectAttachment = new ProjectAttachment()
                            {
                                Id           = Guid.NewGuid(),
                                FileUrl      = newFilenameUrl,
                                CreationDate = DateTime.Now,
                                ProjectId    = project.Id,
                                IsActive     = true,
                                IsDeleted    = false,
                            };
                            db.ProjectAttachments.Add(projectAttachment);
                        }
                    }
                }

                #endregion


                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Title", project.CustomerId);
            return(View(project));
        }
        public async Task <FileResult> DownloadFile(int?id)
        {
            if (id == null)
            {
                return(null);
            }
            ProjectAttachment attachment = await _context.ProjectAttachment.FirstOrDefaultAsync(t => t.Id == id);


            if (attachment == null)
            {
                return(null);
            }
            return(File(attachment.FileData, attachment.ContentType));
        }
        public void SaveUrl(dtoUrl item, String unknownUser)
        {
            if (UserContext.isAnonymous)
            {
                View.DisplaySessionTimeout();
            }
            else
            {
                Boolean isPersonal  = View.isPersonal;
                Int32   idCommunity = View.ProjectIdCommunity;
                Boolean isPortal    = View.forPortal;
                long    idProject   = View.IdProject;
                Person  p           = CurrentManager.GetPerson(UserContext.CurrentUserID);
                ModuleProjectManagement mPermission  = (isPortal) ? ModuleProjectManagement.CreatePortalmodule((p == null) ? (Int32)UserTypeStandard.Guest : p.TypeID) : new ModuleProjectManagement(CurrentManager.GetModulePermission(UserContext.CurrentUserID, idCommunity, CurrentIdModule));
                PmActivityPermission    pPermissions = Service.GetProjectPermission(idProject, UserContext.CurrentUserID);
                Boolean allowSave = (mPermission.Administration && !isPersonal) || ((pPermissions & PmActivityPermission.ManageProject) == PmActivityPermission.ManageProject);

                if (allowSave && item != null)
                {
                    if (String.IsNullOrEmpty(item.Address))
                    {
                        View.SendUserAction(idCommunity, CurrentIdModule, idProject, item.Id, ModuleProjectManagement.ActionType.ProjectAttachmentsUnableToEditUrl);
                        View.DisplayUnableToSaveEmptyUrl(item);
                    }
                    else
                    {
                        ProjectAttachment attachment = Service.AttachmentSaveUrl(item);
                        if (attachment != null)
                        {
                            View.DisplaySavedUrl(item);
                            View.SendUserAction(idCommunity, CurrentIdModule, idProject, item.Id, ModuleProjectManagement.ActionType.ProjectAttachmentsUrlModified);
                        }
                        else
                        {
                            View.SendUserAction(idCommunity, CurrentIdModule, idProject, ModuleProjectManagement.ActionType.ProjectAttachmentsUnableToEditUrl);
                            View.DisplayUnableToSaveUrl(item);
                        }
                    }
                }
                else
                {
                    View.SendUserAction(idCommunity, CurrentIdModule, idProject, ModuleProjectManagement.ActionType.ProjectAttachmentsNoPermissionToEditUrl);
                    View.DisplayNoPermissionToEditUrl();
                }
                LoadAttachments(unknownUser, idProject, isPersonal, idCommunity, mPermission, pPermissions, allowSave, ModuleProjectManagement.ActionType.ProjectAttachmentsReload);
            }
        }
Exemple #22
0
        /// <summary>
        /// Adds the project attachment to list.
        /// </summary>
        /// <param name="projectAttachmentList">The project attachment list.</param>
        /// <param name="rdr">The RDR.</param>
        private static void AddProjectAttachmentToList(ICollection <ProjectAttachment> projectAttachmentList, IDataRecord rdr)
        {
            var projectAttachment = new ProjectAttachment
            {
                Id           = AppHelper.ToInt(rdr["Id"]),
                ProjectId    = AppHelper.ToInt(rdr["ProjectId"]),
                DocumentName = string.Format("{0}", rdr["DocumentName"]),
                Description  = string.Format("{0}", rdr["Description"]),
                Url          = string.Format("{0}", rdr["Url"]),
                CreatedOn    = rdr["CreatedOn"] as DateTime? ?? default(DateTime),
                CreatedBy    = string.Format("{0}", rdr["CreatedBy"]),
                UpdatedOn    = rdr["UpdatedOn"] as DateTime? ?? default(DateTime)
            };

            projectAttachment.CreatedBy = rdr["CreatedBy"] as string;

            projectAttachmentList.Add(projectAttachment);
        }
        private ProjectAttachmentLink GenerateLink(ProjectAttachment attachment, long displayOrder, litePerson person = null, Project project = null, PmActivity activity = null)
        {
            ProjectAttachmentLink link = new ProjectAttachmentLink();

            if (person != null && project != null)
            {
                link.CreateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress);
                link.Project      = project;
                link.Activity     = activity;
                link.Attachment   = attachment;
                link.DisplayOrder = displayOrder;
                link.Type         = AttachmentLinkType.Shared;
                link.IsForProject = (activity == null);
            }
            else
            {
                link = ProjectAttachmentLink.CreateFromAttachment(attachment, displayOrder++);
            }
            return(link);
        }
        public ActionResult Edit(ProjectAttachment viewModel, string command = CommonConstants.ButtonUndefined)
        {
            if (!PatService.GetProject(viewModel.ProjectId).CanAddAttachment(User.Identity.Name.RemoveDomain()))
            {
                return(RedirectToNoAccessAction(viewModel.ProjectId, CommonConstants.ProjectTab_Documents));
            }

            switch (command)
            {
            case CommonConstants.ButtonSave:
                return(Save(viewModel));

            case CommonConstants.ButtonDelete:
                return(Delete(viewModel.Id));

            default:
                AddErrorMessage(string.Format("Button: {0} is not defined. Please refresh your browser and try again.", command));
                return(View(viewModel));
            }
        }
        private List <StandardActionType> GetAllowedStandardActionForFile(int idUser, ModuleObject source, ModuleObject destination)
        {
            List <StandardActionType> actions = new List <StandardActionType>();
            litePerson person   = Manager.Get <litePerson>(idUser);
            Project    project  = ((Int32)ModuleProjectManagement.ObjectType.Project == source.ObjectTypeID) ? Manager.Get <Project>(source.ObjectLongID) : null;
            PmActivity activity = ((Int32)ModuleProjectManagement.ObjectType.Task == source.ObjectTypeID) ? Manager.Get <PmActivity>(source.ObjectLongID) : null;

            if (project == null && activity != null)
            {
                project = activity.Project;
            }
            if (project != null)
            {
                ProjectAttachment attachment = AttachmentGet(project, activity, destination.ObjectLongID);
                if (attachment != null && attachment.Link != null && destination.ObjectLongID == attachment.Item.Id && destination.FQN == attachment.Item.GetType().FullName)
                {
                    dtoAttachmentPermission permissions = AttachmentGetPermissions(person, attachment, project, activity);
                    if (permissions.SetMetadata)
                    {
                        actions.Add(StandardActionType.EditMetadata);
                    }
                    if (permissions.Play)
                    {
                        actions.Add(StandardActionType.Play);
                    }
                    if (permissions.ViewMyStatistics)
                    {
                        actions.Add(StandardActionType.ViewPersonalStatistics);
                    }
                    if (permissions.ViewOtherStatistics)
                    {
                        actions.Add(StandardActionType.ViewAdvancedStatistics);
                    }
                }
            }
            return(actions);
        }
        public ProjectAttachment AttachmentSaveUrl(dtoUrl item)
        {
            ProjectAttachment attachment = null;

            try
            {
                Manager.BeginTransaction();
                attachment = Manager.Get <ProjectAttachment>(item.Id);
                Person person = Manager.GetPerson(UC.CurrentUserID);
                if (attachment != null && attachment.Type == AttachmentType.url && person != null && person.TypeID != (int)UserTypeStandard.Guest && person.TypeID != (int)UserTypeStandard.PublicUser)
                {
                    attachment.UpdateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress);
                    attachment.Url     = item.Address;
                    attachment.UrlName = item.DisplayName;
                    Manager.SaveOrUpdate(attachment);
                }
                Manager.Commit();
            }
            catch (Exception ex) {
                Manager.RollBack();
                attachment = null;
            }
            return(attachment);
        }
        public List <ProjectAttachment> AttachmentsLinkFiles(long idProject, long idActivity, List <ModuleActionLink> links)
        {
            List <ProjectAttachment> attachments = null;
            Boolean isInTransaction = Manager.IsInTransaction();

            try
            {
                if (!isInTransaction)
                {
                    Manager.BeginTransaction();
                }
                PmActivity activity = (idActivity > 0) ? Manager.Get <PmActivity>(idProject) : null;
                Project    project  = (idActivity == 0 && idProject > 0) ? Manager.Get <Project>(idProject) : ((activity == null) ? null : activity.Project);
                Person     person   = Manager.GetPerson(UC.CurrentUserID);
                if (links.Any() && project != null && (idActivity == 0 || activity != null) && person != null && person.TypeID != (int)UserTypeStandard.Guest && person.TypeID != (int)UserTypeStandard.PublicUser)
                {
                    DateTime date   = DateTime.Now;
                    long     dOrder = AttachmentsGetMaxDisplayOrder(project, activity);
                    attachments = new List <ProjectAttachment>();
                    foreach (ModuleActionLink link in links)
                    {
                        ProjectAttachment attachment = (from a in project.Attachments.Where(a => (idActivity == 0 && a.IsForProject) || (!a.IsForProject && a.Activity == activity))
                                                        select a).ToList().Where(a => a.Item == (liteRepositoryItem)link.ModuleObject.ObjectOwner).Skip(0).Take(1).ToList().FirstOrDefault();
                        if (attachment == null)
                        {
                            attachment = new ProjectAttachment();
                            attachment.CreateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, date);
                            attachment.Activity     = activity;
                            attachment.Description  = "";
                            attachment.IsForProject = (activity == null);
                            attachment.Project      = project;
                            attachment.Type         = AttachmentType.file;
                            attachment.Item         = (liteRepositoryItem)link.ModuleObject.ObjectOwner;
                            attachment.Version      = null;

                            Manager.SaveOrUpdate(attachment);
                            ProjectAttachmentLink aLink = GenerateLink(attachment, dOrder++);
                            Manager.SaveOrUpdate(aLink);
                            attachment.SharedItems.Add(aLink);
                            Manager.SaveOrUpdate(attachment);


                            ModuleLink mLink = new ModuleLink(link.Description, link.Permission, link.Action);
                            mLink.CreateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress, date);
                            mLink.DestinationItem = (ModuleObject)link.ModuleObject;
                            mLink.AutoEvaluable   = false;
                            if (attachment.IsForProject)
                            {
                                mLink.SourceItem = ModuleObject.CreateLongObject(project.Id, project, (int)ModuleProjectManagement.ObjectType.Project, (project.Community != null) ? project.Community.Id : 0, ModuleProjectManagement.UniqueCode, GetIdModule());
                            }
                            else
                            {
                                mLink.SourceItem = ModuleObject.CreateLongObject(activity.Id, activity, (int)ModuleProjectManagement.ObjectType.Task, (project.Community != null) ? project.Community.Id : 0, ModuleProjectManagement.UniqueCode, GetIdModule());
                            }
                            Manager.SaveOrUpdate(mLink);
                            attachment.Link = Manager.Get <liteModuleLink>(mLink.Id);
                            Manager.SaveOrUpdate(attachment);
                            if (activity == null)
                            {
                                project.Attachments.Add(attachment);
                            }
                            project.AttachmentLinks.Add(aLink);
                        }
                        else if (attachment.Deleted != BaseStatusDeleted.None)
                        {
                            attachment.RecoverMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, date);
                            foreach (ProjectAttachmentLink l in attachment.SharedItems.Where(s => s.Type == AttachmentLinkType.Owner))
                            {
                                l.DisplayOrder = dOrder++;
                                l.RecoverMetaInfo(person.Id, attachment.ModifiedIpAddress, attachment.ModifiedProxyIpAddress, attachment.ModifiedOn);
                            }
                        }

                        attachments.Add(attachment);
                    }
                }
                if (!isInTransaction)
                {
                    Manager.Commit();
                }
            }
            catch (Exception ex)
            {
                if (!isInTransaction)
                {
                    Manager.RollBack();
                }
                attachments = null;
            }
            return(attachments);
        }
        public List <ProjectAttachment> AttachmentsAddFiles(Project project, PmActivity activity, List <dtoModuleUploadedItem> items)
        {
            List <ProjectAttachment> attachments = null;
            Boolean isInTransaction = Manager.IsInTransaction();

            try
            {
                if (!isInTransaction)
                {
                    Manager.BeginTransaction();
                }
                Person person = Manager.GetPerson(UC.CurrentUserID);
                if (items.Any() && project != null && person != null && person.TypeID != (int)UserTypeStandard.Guest && person.TypeID != (int)UserTypeStandard.PublicUser)
                {
                    long dOrder = AttachmentsGetMaxDisplayOrder(project, activity);
                    attachments = new List <ProjectAttachment>();
                    DateTime date = DateTime.Now;
                    foreach (dtoModuleUploadedItem item in items)
                    {
                        ProjectAttachment attachment = new ProjectAttachment();
                        attachment.CreateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, date);
                        attachment.Activity     = activity;
                        attachment.Description  = "";
                        attachment.IsForProject = (activity == null);
                        attachment.Project      = project;
                        attachment.Type         = AttachmentType.file;
                        attachment.Item         = item.ItemAdded;
                        Manager.SaveOrUpdate(attachment);
                        ProjectAttachmentLink aLink = GenerateLink(attachment, dOrder++);
                        Manager.SaveOrUpdate(aLink);
                        attachment.SharedItems.Add(aLink);
                        Manager.SaveOrUpdate(attachment);
                        ModuleLink link = new ModuleLink(item.Link.Description, item.Link.Permission, item.Link.Action);
                        link.CreateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress, date);
                        link.DestinationItem = (ModuleObject)item.Link.ModuleObject;
                        link.AutoEvaluable   = false;
                        if (attachment.IsForProject)
                        {
                            link.SourceItem = ModuleObject.CreateLongObject(project.Id, project, (int)ModuleProjectManagement.ObjectType.Project, (project.Community != null) ? project.Community.Id : 0, ModuleProjectManagement.UniqueCode, GetIdModule());
                        }
                        else
                        {
                            link.SourceItem = ModuleObject.CreateLongObject(activity.Id, activity, (int)ModuleProjectManagement.ObjectType.Task, (project.Community != null) ? project.Community.Id : 0, ModuleProjectManagement.UniqueCode, GetIdModule());
                        }
                        Manager.SaveOrUpdate(link);
                        attachment.Link = Manager.Get <liteModuleLink>(link.Id);
                        Manager.SaveOrUpdate(attachment);
                        attachments.Add(attachment);
                        if (activity == null)
                        {
                            project.Attachments.Add(attachment);
                        }
                        project.AttachmentLinks.Add(aLink);
                    }
                }
                if (!isInTransaction)
                {
                    Manager.Commit();
                }
            }
            catch (Exception ex)
            {
                if (!isInTransaction)
                {
                    Manager.RollBack();
                }
                attachments = null;
            }
            return(attachments);
        }
        public List <ProjectAttachment> AttachmentsAddUrl(long idProject, long idActivity, List <dtoUrl> urls)
        {
            List <ProjectAttachment> attachments = null;
            Boolean isInTransaction = Manager.IsInTransaction();

            try
            {
                if (!isInTransaction)
                {
                    Manager.BeginTransaction();
                }
                Person person = Manager.GetPerson(UC.CurrentUserID);
                if (urls != null && urls.Where(u => !String.IsNullOrEmpty(u.Address)).Any() && person != null && person.TypeID != (int)UserTypeStandard.Guest && person.TypeID != (int)UserTypeStandard.PublicUser)
                {
                    PmActivity activity = (idActivity > 0) ? Manager.Get <PmActivity>(idActivity) : null;
                    Project    project  = (idActivity == 0 && idProject > 0) ? Manager.Get <Project>(idProject) : ((activity == null) ? null : activity.Project);
                    if (project != null && (idActivity == 0 || activity != null))
                    {
                        long     dOrder = AttachmentsGetMaxDisplayOrder(project, activity);
                        DateTime date   = DateTime.Now;
                        attachments = new List <ProjectAttachment>();
                        foreach (dtoUrl item in urls.Where(u => !String.IsNullOrEmpty(u.Address) && Uri.IsWellFormedUriString(u.Address, UriKind.RelativeOrAbsolute)))
                        {
                            ProjectAttachment attachment = new ProjectAttachment();
                            attachment.CreateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, date);
                            attachment.Activity     = activity;
                            attachment.Description  = "";
                            attachment.IsForProject = (activity == null);
                            attachment.Project      = project;
                            attachment.Type         = AttachmentType.url;
                            attachment.Url          = item.Address;
                            attachment.UrlName      = item.Name;
                            Manager.SaveOrUpdate(attachment);

                            ProjectAttachmentLink aLink = GenerateLink(attachment, dOrder++);
                            Manager.SaveOrUpdate(aLink);
                            attachment.SharedItems.Add(aLink);
                            attachments.Add(attachment);
                            if (idActivity == 0)
                            {
                                project.Attachments.Add(attachment);
                            }
                            project.AttachmentLinks.Add(aLink);
                        }
                    }
                }
                if (!isInTransaction)
                {
                    Manager.Commit();
                }
            }
            catch (Exception ex)
            {
                if (!isInTransaction)
                {
                    Manager.RollBack();
                }
                attachments = null;
            }
            return(attachments);
        }
        private PartialViewResult ViewDelete(ProjectAttachment projectAttachment, ConfirmDialogFormViewModel viewModel)
        {
            var viewData = new ConfirmDialogFormViewData($"Are you sure you want to delete \"{projectAttachment.DisplayName}\" from this {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()}?", true);

            return(RazorPartialView <ConfirmDialogForm, ConfirmDialogFormViewData, ConfirmDialogFormViewModel>(viewData, viewModel));
        }