public IHttpActionResult AdminChangeProjectStatus(ProjectEditDTO project) { bool result = false; try { // Check authen. if (User.Identity == null || !User.Identity.IsAuthenticated) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.NOT_AUTHEN }); } if (project == null) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.BAD_REQUEST }); } // Check role user. var currentUser = UserRepository.Instance.GetBasicInfo(User.Identity.Name); if (currentUser == null || currentUser.Role != DDLConstants.UserType.ADMIN) { throw new NotPermissionException(); } result = ProjectRepository.Instance.AdminChangeProjectStatus(project, User.Identity.Name); } catch (Exception) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.BAD_REQUEST }); } return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.SUCCESS, Message = "", Type = "", Data = result }); }
public IHttpActionResult EditProject(int ProjectID, ProjectEditDTO project) { if (project == null) { return Ok(new HttpMessageDTO { Status = "error", Message = "", Type = "Bad-Request" }); } var updateProject = ProjectRepository.Instance.EditProject(ProjectID, project); return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.SUCCESS, Message = "", Type = "" }); }
public IHttpActionResult SubmitProject(ProjectEditDTO project) { List<string> errorList = null; try { // Check authen. if (User.Identity == null || !User.Identity.IsAuthenticated) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.NOT_AUTHEN }); } int flag = 0; if (project == null) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.BAD_REQUEST }); } if (project.Status != DDLConstants.ProjectStatus.DRAFT && project.Status != DDLConstants.ProjectStatus.REJECTED) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.BAD_REQUEST }); } errorList = ProjectRepository.Instance.SubmitProject(project, User.Identity.Name); foreach (var error in errorList) { if (!string.IsNullOrEmpty(error)) { flag = 1; } } if (flag == 0) { project.Status = DDLConstants.ProjectStatus.PENDING; } else { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = "", Data = errorList }); } } catch (KeyNotFoundException) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.NOT_FOUND }); } catch (NotPermissionException) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.NOT_AUTHEN }); } catch (Exception) { return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.ERROR, Message = "", Type = DDLConstants.HttpMessageType.BAD_REQUEST }); } return Ok(new HttpMessageDTO { Status = DDLConstants.HttpMessageType.SUCCESS, Message = DDLConstants.HttpMessageType.SUCCESS, Type = "", Data = project }); }
// Check pending project protected void DetechPendingProject() { using (var db = new DDLDataContext()) { var projects = db.Projects.Where(x => x.Status == DDLConstants.ProjectStatus.PENDING).ToList(); foreach (var project in projects) { var timespan = DateTime.UtcNow - project.CreatedDate; if (timespan.Days > 3) { var detectedProject = new ProjectEditDTO { ProjectID = project.ProjectID, Status = DDLConstants.ProjectStatus.REJECTED }; var result = ProjectRepository.Instance.AdminChangeProjectStatus(detectedProject, "admin001"); } //db.SaveChanges(); } } }