Beispiel #1
0
        public async Task <JobsDto> CreateJobSetup(CreateJobViewModel createJob)
        {
            var job = new Jobs(createJob);

            job.Company = await _companyRepository.Get(createJob.CompanyId);

            if (createJob.Employees.Count > 0)
            {
                foreach (var employeeId in createJob.Employees)
                {
                    Employee employee = await _employeeRepository.Get(employeeId);

                    job.JobsEmployees.Add(new JobsEmployee()
                    {
                        JobsId = job.Id, EmployeeId = employeeId, Employee = employee
                    });
                }
            }

            var createdJob = await _jobsRepository.Create(job);

            var jobToView = _mapper.Map <Jobs, JobsDto>(createdJob);

            return(jobToView);
        }
        public JobDto Create(string fileName, Guid guid)
        {
            var job = new JobDto
            {
                FileName  = fileName,
                JobId     = guid,
                JobStatus = EnumUtility.GetValue(JobStatus.Created)
            };

            return(_jobsRepository.Create(job));
        }
Beispiel #3
0
        public async Task <ActionResult> Create(CreateJobViewModel jobToCreate)
        {
            var clients = await clientRepository.GetAllClients();

            var sites = await siteRepository.GetAll();

            var mappedJob = jobToCreate.Job;
            var createDto = new CreateJobDto()
            {
                ClientId    = jobToCreate.SelectedClientId,
                JobCode     = jobToCreate.Job.JobCode,
                JobName     = jobToCreate.Job.JobName,
                JobStatusId = (JobStatus)jobToCreate.SelectedJobStatusId,
                ProjectManagerEmployeeId = jobToCreate.SelectedProjectManagerEmployeeId,
                SiteId      = jobToCreate.SelectedSiteId,
                TargetHours = jobToCreate.Job.TargetHours,
            };

            await _jobsRepository.Create(createDto);

            NotificationsController.AddNotification(User.SafeUserName(), $"Sucessfully created {jobToCreate.Job.FullJobCodeWithName}");
            return(RedirectToAction(nameof(Index)));
        }
Beispiel #4
0
        public async Task <ActionResult <IEnumerable <CoreJobDto> > > SaveBulkJobs([FromBody] IEnumerable <JobUploadModel> jobs)
        {
            var res = new JobUploadResults()
            {
                NewClients = new Dictionary <string, int>(),
                NewSites   = new Dictionary <string, int>(),
            };

            try
            {
                var allSites = await _sitesRepository.GetAll();

                var sitesBySiteName = await BulkSaveSites(allSites, jobs, newSite => res.NewSites.TryAdd(newSite.SiteName, newSite.SiteID));

                var allClients = await _clientsRepository.GetAllClients();

                var clientsByClientName = await BulkSaveClients(allClients, jobs, newClient => res.NewClients.TryAdd(newClient.ClientName, newClient.ClientId));

                var allJobs = await _jobsRepository.GetAsync();

                var newJobs      = new List <CoreJobDto>();
                var updatedJobs  = new List <CoreJobDto>();
                var skippedEntry = new List <CoreJobDto>();
                foreach (var rec in jobs)
                {
                    var isBrandNewJob = false;
                    var temp          = rec;
                    var matchedJob    = await SaveForMatchingField(allJobs,
                                                                   matchCriteria : (existingJob, newJob) => {
                        var wtf = existingJob.JobCode.Replace("-", "").Equals(newJob.JobCode.Replace("-", ""), StringComparison.InvariantCultureIgnoreCase);
                        return(wtf);
                    },
                                                                   factory : async(newJob) =>
                    {
                        var created = await _jobsRepository.Create(new BLL.Jobs.CreateJobDto()
                        {
                            ClientId    = clientsByClientName[newJob.ClientName.Trim()],
                            JobCode     = newJob.JobCode,
                            JobName     = newJob.JobName,
                            JobStatusId = JobStatus.Enabled,
                            SiteId      = sitesBySiteName[newJob.SiteName.Trim()],
                            ProjectManagerEmployeeId = newJob.ProjectManager ?? 1
                        });
                        isBrandNewJob = true;

                        return(created);
                    },
                                                                   field : temp);

                    var nameChanged   = matchedJob.JobName != rec.JobName;
                    var clientChanged = matchedJob.ClientId != clientsByClientName[rec.ClientName.Trim()];
                    var siteChanged   = matchedJob.SiteId != sitesBySiteName[rec.SiteName.Trim()];
                    if (isBrandNewJob)
                    {
                        newJobs.Add(matchedJob);
                    }
                    else if (nameChanged || clientChanged || siteChanged)
                    {
                        matchedJob.JobName  = rec.JobName;
                        matchedJob.ClientId = clientsByClientName[rec.ClientName.Trim()];
                        matchedJob.SiteId   = sitesBySiteName[rec.SiteName.Trim()];
                        await _jobsRepository.Update(matchedJob);

                        updatedJobs.Add(matchedJob);
                    }
                    else
                    {
                        skippedEntry.Add(matchedJob);
                    }
                }

                res.UpdatedJobs = updatedJobs;
                res.CreatedJobs = newJobs;
                res.SkippedEntriesBecuaseNoChange = skippedEntry;
            }
            catch (Exception e)
            {
                return(new ObjectResult(new
                {
                    Error = new ProblemDetails()
                    {
                        Title = e.Message,
                        Detail = e.ToString(),
                        Instance = this.HttpContext.Request.GetDisplayUrl(),
                        Status = StatusCodes.Status500InternalServerError,
                        Type = "Unhandled Error"
                    },
                    Processed = res
                }));
            }


            return(Ok(res));
        }