Exemplo n.º 1
0
        /// <summary>
        /// Get requirement by name.
        /// </summary>
        /// <param name="context">Context of the database.</param>
        /// <param name="requirement">Requirement that contains the name field to filter by.</param>
        /// <returns>A DTO requirement.</returns>
        public DTORequirements getRequirementByName(IDbContext context, DTORequirements requirement)
        {
            var query = getAllByProjectId(context, requirement)
                        .Where(x => x.Name == requirement.Name && x.ProjectId == requirement.ProjectId).FirstOrDefault();

            return(Mapper.mapDTORequirements(query));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Get json for datatable in requirements.
 /// </summary>
 /// <param name="requirement">Requirement that contains the projectId.</param>
 /// <param name="dataTableparms">Parameters sent from ajax.</param>
 /// <returns>A DataTableJson object.</returns>
 public DataTableJson <DTORequirementDataTable> getJsonDataTable(DTORequirements requirement, DataTableParams dataTableparms)
 {
     using (DbContext)
     {
         var query = requirementRepository.getJsonDataTable(DbContext, requirement, dataTableparms);
         return(query);
     }
 }
Exemplo n.º 3
0
        public DTORequirements insertAndgetRequirement(DTORequirements DTORequirement)
        {
            int idOfInsertedRequirement = Container.createIRequirementsRepository().insertRequirementAndSaveChanges(Container.createIDbContext(), DTORequirement);

            DTORequirement.Id = idOfInsertedRequirement;

            return(DTORequirement);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Add error to modelState if the name already exists.
        /// </summary>
        /// <param name="dbContext">Context of the database.</param>
        /// <param name="requirement">The requirement that contains the name to be validated.</param>
        private void addErrorIfNameExist(DTORequirements requirement)
        {
            bool nameExist = requirementRepository.getRequirementByName(DbContext, requirement) != null;

            if (nameExist)
            {
                ControllerUI.ModelStateService.AddModelError("Name", GlobalResources["nameEntity"]);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Insert a requirement in the db.
        /// </summary>
        /// <param name="context">Context of the database.</param>
        /// <param name="requirement">Requirement DTO to be inserted.</param>
        /// <returns>The id of the inserted record.</returns>
        public int insertRequirementAndSaveChanges(IDbContext context, DTORequirements requirement)
        {
            throwExceptionIfForeignKeyInvalid(requirement.ProjectId);

            // Get entity from DTO
            var requirementEntity = Mapper.mapEntityRequirements(requirement);

            // Return id
            return(insertAndSaveChanges <Requirement>(context, requirementEntity));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Get project name by project id.
        /// </summary>
        /// <param name="context">Context of the database.</param>
        /// <param name="requirement">Requirement that contains the projectId to filterby.</param>
        /// <returns>The name of the project</returns>
        public DTOProject getProjectNameAndIdByRequirement(IDbContext context, DTORequirements requirement)
        {
            var query = getAll <Project>(context)
                        .Where(x => x.Id == requirement.ProjectId)
                        .Select(x => new { x.Name, x.Id })
                        .AsEnumerable().Select(x => new DTOProject
            {
                Name = x.Name,
                Id   = x.Id
            }).FirstOrDefault();

            return(query);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Check if a requirement can be deleted.
        /// </summary>
        /// <param name="requirement">Requirement to be checked.</param>
        /// <returns></returns>
        private bool deleteRequirementIsOk(DTORequirements requirement)
        {
            var existTasksForThisReq = taskRepository.tasksExistByRequirementId(DbContext, new DTOTask {
                RequirementId = requirement.Id
            });

            if (existTasksForThisReq)
            {
                ControllerUI.ModelStateService.AddModelError(SummaryError, GlobalResources["deleteRequirement"]);
            }

            return(ControllerUI.ModelStateService.IsValid);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Get all the requirement DTO by all fields except for the id.
        /// </summary>
        /// <param name="context">Context of the database.</param>
        /// <param name="requirement">Requirement DTO.</param>
        /// <returns>A collection of requirement DTO matching the criteria.</returns>
        public List <DTORequirements> getByAllFieldsExceptId(IDbContext context, DTORequirements requirement)
        {
            var query = getAllByProjectId(context, requirement)
                        .Where(x =>
                               x.Description == requirement.Description &&
                               x.Name == requirement.Name &&
                               x.IsComplete == requirement.IsComplete
                               ).AsEnumerable().Select(x =>
                                                       Mapper.mapDTORequirements(x)
                                                       ).ToList();

            return(query);
        }
Exemplo n.º 9
0
        // Task
        public DTOTask getRandomTask(DTORequirements requirement)
        {
            var randonDescription  = "descrp-" + getRString();
            var randonCreationDate = getRandomDate();
            var taskToInsert       = new DTOTask
            {
                RequirementId = requirement.Id,
                Description   = randonDescription,
                CreationDate  = randonCreationDate
            };

            return(taskToInsert);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Delete a requirement.
        /// </summary>
        /// <param name="requirement">Requirement to be deleted.</param>
        public void deleteRequirement(DTORequirements requirement)
        {
            using (DbContext)
            {
                // Validate if the requirement can be deleted
                if (!deleteRequirementIsOk(requirement))
                {
                    return;
                }

                // Delete requirement
                requirementRepository.deleteRequirement(DbContext, requirement);
                DbContext.SaveChanges();
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Get all the requirements.
        /// </summary>
        /// <returns>A collection of DTO requirements.</returns>
        public DTORequirementView getAllRequirements(DTORequirements requirement)
        {
            using (DbContext)
            {
                // Get requirements and project name
                var project = requirementRepository.getProjectNameAndIdByRequirement(DbContext, requirement);

                // Return requirement view
                return(new DTORequirementView
                {
                    ProjectId = requirement.ProjectId,
                    ProjectName = project.Name,
                });
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Update a requirement.
        /// </summary>
        /// <param name="context">Context of the database.</param>
        /// <param name="requirement">Requirement to update.</param>
        public void updateRequirement(IDbContext context, DTORequirements requirement)
        {
            // Old entity
            var oldEntity = context.Requirements.Where(x => x.Id == requirement.Id).FirstOrDefault();

            // New entity and set fk and dates
            var newEntity = Mapper.mapEntityRequirements(requirement);

            newEntity.ProjectId        = oldEntity.ProjectId;
            newEntity.CreationDate     = oldEntity.CreationDate;
            newEntity.FinalizationDate = oldEntity.FinalizationDate;

            // Update entity
            update <Requirement>(context, newEntity, oldEntity);
        }
Exemplo n.º 13
0
        public DTORequirements getRandomRequirement(DTOProject project)
        {
            var randonName          = "req-" + getRString().ToString();
            var randonDescription   = "desp-" + getRString().ToString();
            var randonCreationDate  = getRandomDate();
            var requirementToInsert = new DTORequirements
            {
                ProjectId        = project.Id,
                Name             = randonName,
                Description      = randonDescription,
                CreationDate     = randonCreationDate,
                FinalizationDate = (DateTime)SqlDateTime.MaxValue
            };

            return(requirementToInsert);
        }
Exemplo n.º 14
0
        public List <DTOTask> insertTasksAndgetList(DTORequirements requirement, int listLength)
        {
            List <DTOTask> taskList = new List <DTOTask>();

            for (int i = 0; i < listLength; i++)
            {
                // Get individual task
                var taskToInsert = getRandomTask(requirement);

                // Insert task
                int insertedRecord = Container.createITaskRepository().insertTaskAndSaveChanges(Container.createIDbContext(), taskToInsert);
                taskToInsert.Id = insertedRecord;

                // Add task to list
                taskList.Add(taskToInsert);
            }

            return(taskList);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Insert a requirement in db.
        /// </summary>
        /// <param name="Requirement">Requirement to be inserted.</param>
        /// <returns>The id of the inserted record.</returns>
        public int insertRequirement(DTORequirements Requirement)
        {
            using (DbContext)
            {
                // Validate insert requirement
                if (!insertRequirementIsOk(Requirement))
                {
                    return(-1);
                }

                // Set dates
                Requirement.CreationDate     = DateTime.Now;
                Requirement.FinalizationDate = (DateTime)SqlDateTime.MinValue;

                // Insert requirement
                int id = requirementRepository.insertRequirementAndSaveChanges(DbContext, Requirement);
                return(id);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Update a requirement.
        /// </summary>
        /// <param name="requirement">Requirement to update.</param>
        public void updateRequirement(DTORequirements requirement)
        {
            using (DbContext)
            {
                // Validate requirement to update
                if (!updateRequirementIsOk(requirement))
                {
                    return;
                }

                // Set creation and finalization date
                var oldRequirement = requirementRepository.getRequirementById(DbContext, requirement);
                requirement.CreationDate     = oldRequirement.CreationDate;
                requirement.FinalizationDate = oldRequirement.FinalizationDate;

                // Update requirement and save changes
                requirementRepository.updateRequirement(DbContext, requirement);
                DbContext.SaveChanges();
            }
        }
Exemplo n.º 17
0
        public ActionResult DataTableAjaxHandler(DTORequirements requirement, DataTableParams dataTableParams)
        {
            var data = requirementService.getJsonDataTable(requirement, dataTableParams);

            return(Json(data, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Get a requirement by id.
        /// </summary>
        /// <param name="context">Context of the database.</param>
        /// <param name="id">Id of the requirement to get.</param>
        /// <returns>A requirement DTO.</returns>
        public DTORequirements getRequirementById(IDbContext context, DTORequirements requirement)
        {
            var query = getById <Requirement>(context, Mapper.mapEntityRequirements(requirement)).FirstOrDefault();

            return(Mapper.mapDTORequirements(query));
        }
Exemplo n.º 19
0
 /// <summary>
 /// Delete a requirement.
 /// </summary>
 /// <param name="context">Context of the database.</param>
 /// <param name="requirement">Requirement to remove.</param>
 public void deleteRequirement(IDbContext context, DTORequirements requirement)
 {
     // Delete entity
     delete <Requirement>(context, Mapper.mapEntityRequirements(requirement));
 }
Exemplo n.º 20
0
        /// <summary>
        /// Get all the requirements as iqueryable and by project id.
        /// </summary>
        /// <param name="context">context of the database.</param>
        /// <param name="requirement">Requirement that contains the project id fk.</param>
        /// <returns>An iqueryable collection.</returns>
        private IQueryable <Requirement> getAllByProjectId(IDbContext context, DTORequirements requirement)
        {
            throwExceptionIfForeignKeyInvalid(requirement.ProjectId);

            return(getAll <Requirement>(context).Where(x => x.ProjectId == requirement.ProjectId).AsQueryable());
        }
Exemplo n.º 21
0
        /// <summary>
        /// Check if a requirement exist.
        /// </summary>
        /// <param name="context">Context of the database.</param>
        /// <param name="requirement">Requiremet to check in db.</param>
        /// <returns>True if the requirement exist. Otherwise false.</returns>
        public bool requirementExistsByProjectId(IDbContext context, DTORequirements requirement)
        {
            var query = getAll <Requirement>(context).Where(x => x.ProjectId == requirement.ProjectId).Any();

            return(query);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Validate the insert requirement method.
        /// </summary>
        /// <param name="dbContext">Context of the database.</param>
        /// <param name="requirement">Requirement to be validated.</param>
        /// <returns>True if validation is successful. Otherwise false.</returns>
        private bool insertRequirementIsOk(DTORequirements requirement)
        {
            addErrorIfNameExist(requirement);

            return(ControllerUI.ModelStateService.IsValid);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Get json datatable for requirements.
        /// </summary>
        /// <param name="context">Context of the database.</param>
        /// <param name="requirement">Requirement that contains the projectId</param>
        /// <param name="dataTableparms"></param>
        /// <returns></returns>
        public DataTableJson <DTORequirementDataTable> getJsonDataTable(IDbContext context, DTORequirements requirement, DataTableParams dataTableparms)
        {
            // Get requirement as a list of DTORequirementDataTable
            var requirementsDataTable = getAllByProjectId(context, requirement)
                                        .Select(x => new DTORequirementDataTable
            {
                RequirementId = x.Id,
                ProjectId     = x.ProjectId,
                CreationDate  = x.CreationDate,
                Description   = x.Description,
                Name          = x.Name,
                NumberOfTasks = 0,
                ThereAreTasks = false
            }).AsQueryable();

            // Get the filtering
            Expression <Func <DTORequirementDataTable, bool> > filtering = getFilteringForReqDataTable(dataTableparms);

            // Get json
            var iqueryableSource = dataTableService.getIQueryableSource <DTORequirementDataTable>
                                   (
                dataTableparms,
                requirementsDataTable,
                filtering
                                   );

            // Get status
            var listWithStatus = getStatusInListDTORequirementDataTable(context, iqueryableSource);

            // Return json response
            return(dataTableService.getJsonResponse <DTORequirementDataTable>(listWithStatus));
        }
Exemplo n.º 24
0
 /// <summary>
 /// Map DTO requiremnets to entity requirement.
 /// </summary>
 /// <param name="dtoRequirement">Entity requirement to map from.</param>
 /// <returns>A DTO requirement.</returns>
 public Requirement mapEntityRequirements(DTORequirements dtoRequirement)
 {
     return(map <Requirement>(dtoRequirement));
 }
Exemplo n.º 25
0
 public ActionResult DeleteRequirement(DTORequirements requirement)
 {
     requirementService.deleteRequirement(requirement);
     return(Json(true));
 }
Exemplo n.º 26
0
 public ActionResult Index(DTORequirements requirement)
 {
     return(View("Index", requirementService.getAllRequirements(requirement)));
 }
Exemplo n.º 27
0
        public ActionResult CreateRequirement([Bind(Exclude = "Id")] DTORequirements requirement)
        {
            int id = requirementService.insertRequirement(requirement);

            return(Json(id));
        }
Exemplo n.º 28
0
        // Private Methods =====================================
        private IQueryable <DTORequirementDataTable> getRequirementDataTableIQueryable(DTORequirements requirement)
        {
            // Get requirement as a list of DTORequirementDataTable
            var requirementsDataTable = Container.createIDbContext().Requirements.Where(x => x.ProjectId == requirement.ProjectId)
                                        .Select(x => new DTORequirementDataTable
            {
                RequirementId = x.Id,
                ProjectId     = x.ProjectId,
                CreationDate  = x.CreationDate,
                Description   = x.Description,
                Name          = x.Name,
                NumberOfTasks = 0,
            }).AsQueryable();

            return(requirementsDataTable);
        }