예제 #1
0
        public async Task <ApiResponse> Handle(EditProjectSubActivityDetailCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                ProjectActivityDetail obj = await _dbContext.ProjectActivityDetail.FirstOrDefaultAsync(x => x.ActivityId == request.ActivityId && x.IsDeleted == false);

                if (obj != null)
                {
                    obj.ActivityDescription    = request.ActivityDescription;
                    obj.ChallengesAndSolutions = request.ChallengesAndSolutions;
                    obj.EmployeeID             = request.EmployeeID;
                    obj.IsCompleted            = request.IsCompleted;
                    obj.BudgetLineId           = request.BudgetLineId;
                    obj.Achieved         = request.Achieved;
                    obj.Target           = request.Target;
                    obj.ModifiedDate     = request.ModifiedDate;
                    obj.IsDeleted        = false;
                    obj.ModifiedById     = request.ModifiedById;
                    obj.SubActivityTitle = request.SubActivityTitle;
                    await _dbContext.SaveChangesAsync();
                }
                response.data.ProjectActivityDetail = obj;
                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
            }
            return(response);
        }
예제 #2
0
        public async Task <ApiResponse> Handle(EndProjectSubActivityCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                ProjectActivityDetail obj = await _dbContext.ProjectActivityDetail.FirstOrDefaultAsync(x => x.ActivityId == request.activityId && x.IsDeleted == false);

                if (obj != null)
                {
                    obj.ActualEndDate = DateTime.UtcNow;
                    obj.ModifiedDate  = request.ModifiedDate;
                    obj.IsDeleted     = false;
                    obj.ModifiedById  = request.ModifiedById;
                    await _dbContext.SaveChangesAsync();
                }

                response.data.ProjectActivityDetail = obj;
                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
            }
            return(response);
        }
        public async Task <ApiResponse> Handle(AddProjectSubActivityDetailCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                ProjectActivityDetail obj = _mapper.Map <AddProjectSubActivityDetailCommand, ProjectActivityDetail>(request);
                //Note : check for all the subactivity are completed or not.
                ProjectActivityDetail parent = await _dbContext.ProjectActivityDetail
                                               .FirstOrDefaultAsync(x => x.IsDeleted == false &&
                                                                    x.ActivityId == request.ParentId &&
                                                                    x.StatusId == (int)ProjectPhaseType.Completed);

                obj.StatusId    = (int)ProjectPhaseType.Planning;
                obj.CreatedDate = request.CreatedDate;
                obj.IsDeleted   = false;
                obj.CreatedById = request.CreatedById;
                await _dbContext.ProjectActivityDetail.AddAsync(obj);

                await _dbContext.SaveChangesAsync();

                ProjectActivityModel actvityModel = new ProjectActivityModel()
                {
                    ActivityDescription = obj.ActivityDescription,
                    ActivityId          = obj.ActivityId,
                    StatusId            = obj.StatusId,
                    ActivityName        = obj.ActivityName,
                    ActualEndDate       = obj.ActualEndDate,
                    ActualStartDate     = obj.ActualStartDate,
                    BudgetLineId        = obj.BudgetLineId,
                    ParentId            = obj.ParentId,
                    Target           = obj.Target,
                    PlannedEndDate   = obj.PlannedEndDate,
                    PlannedStartDate = obj.PlannedStartDate,
                    EmployeeID       = obj.EmployeeID,
                    SubActivityTitle = obj.SubActivityTitle
                };

                if (parent != null)
                {
                    parent.StatusId = (int)ProjectPhaseType.Implementation;
                    await _dbContext.SaveChangesAsync();

                    actvityModel.StatusId = parent.StatusId;
                }
                response.data.ProjectActivityModel = actvityModel;
                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
            }
            return(response);
        }
예제 #4
0
        public async Task <ApiResponse> Handle(ProjectSubActivityIscompleteCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                ProjectActivityDetail obj = await _dbContext.ProjectActivityDetail.FirstOrDefaultAsync(x => x.ActivityId == request.activityId && x.IsDeleted == false);

                if (obj != null)
                {
                    obj.IsCompleted  = !obj.IsCompleted;
                    obj.ModifiedDate = request.ModifiedDate;
                    obj.IsDeleted    = false;
                    obj.ModifiedById = request.ModifiedById;
                    await _dbContext.SaveChangesAsync();
                }
                var parent = await _dbContext.ProjectActivityDetail.AnyAsync(x => x.IsDeleted == false &&
                                                                             x.ParentId == obj.ParentId &&
                                                                             x.IsCompleted == false);

                ProjectActivityDetail detail = new ProjectActivityDetail();
                if (!parent)
                {
                    //foreach (var item in parent)
                    //{
                    detail = await _dbContext.ProjectActivityDetail.FirstOrDefaultAsync(x => x.IsDeleted == false && x.ActivityId == obj.ParentId);

                    if (detail != null)
                    {
                        detail.StatusId = (int)ProjectPhaseType.Completed;
                        await _dbContext.SaveChangesAsync();
                    }
                    //}
                }
                response.data.ProjectActivityDetail = detail;
                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
            }
            return(response);
        }
        public async Task <ApiResponse> Handle(AddProjectActivityDetailCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                ProjectActivityDetail obj = _mapper.Map <AddProjectActivityDetailCommand, ProjectActivityDetail>(request);
                obj.CreatedDate = DateTime.UtcNow;
                obj.IsDeleted   = false;
                obj.CreatedById = request.CreatedById;
                await _dbContext.ProjectActivityDetail.AddAsync(obj);

                await _dbContext.SaveChangesAsync();

                if (request.ProvinceId != null)
                {
                    List <ProjectActivityProvinceDetail> activityProvienceList = new List <ProjectActivityProvinceDetail>();

                    var districts = _dbContext.DistrictDetail.Where(x => x.IsDeleted == false && request.ProvinceId.Contains(x.ProvinceID.Value)).ToList();

                    var selectedDistrict = districts.Where(x => request.DistrictID.Contains(x.DistrictID))
                                           .Select(x => new ProjectActivityProvinceDetail
                    {
                        DistrictID = x.DistrictID,
                        ProvinceId = x.ProvinceID.Value
                    }).ToList();

                    // var provincesWithNoDistrict= selectedDistrict.Where(x => !model.ProvinceId.Contains(x.ProvinceId));

                    var provincesWithNoDistrict = request.ProvinceId.Where(x => !selectedDistrict.Select(y => y.ProvinceId).Contains(x)).ToList();

                    foreach (var item in provincesWithNoDistrict)
                    {
                        ProjectActivityProvinceDetail projectActivityProvinceDetail = new ProjectActivityProvinceDetail();
                        projectActivityProvinceDetail.ProvinceId = item;
                        selectedDistrict.Add(projectActivityProvinceDetail);
                    }

                    foreach (var item in selectedDistrict)
                    {
                        item.ActivityId  = obj.ActivityId;
                        item.CreatedById = request.CreatedById;
                        item.CreatedDate = request.CreatedDate;
                        item.IsDeleted   = false;
                    }
                    // await _uow.ProjectActivityProvinceDetailRepository.A(obj);
                    await _dbContext.ProjectActivityProvinceDetail.AddRangeAsync(selectedDistrict);

                    await _dbContext.SaveChangesAsync();
                }

                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
            }
            return(response);
        }