public async System.Threading.Tasks.Task <ActionResult> List() { var isAdmin = User.IsInRole(UserRoleName.Admin); var jobs = await _jobsRepository.GetAsync(); if (!isAdmin) { jobs = jobs.Where(x => x.JobStatusId == JobStatus.Enabled).ToList(); } var myJobs = await _jobsRepository.GetAsync(await sessionAdapter.EmployeeIdAsync()); var availableClients = await clientRepository.GetAllClients(); var availableSites = await siteRepository.GetAll(); var allEmployees = await _employeeRepository.GetAllEmployees(); var models = jobs.OrderBy(x => x.JobCode).Select(job => { var details = new JobModelDetail { Client = _mapper.Map <ClientModel>(availableClients.SingleOrDefault(z => z.ClientId == job.ClientId)), Site = _mapper.Map <SiteModel>(availableSites.SingleOrDefault(z => z.SiteID == job.SiteId)), ProjectManager = _mapper.Map <ProjectManagerModel>(allEmployees.SingleOrDefault(z => z.EmployeeId == job.ProjectManagerEmployeeId)) }; return(job, details); }).ToList(); var vm = new JobListViewModel() { AllJobsWithAssociationStatus = models.OrderBy(x => x.job.JobCode) .ToDictionary(x => x, x => myJobs.Any(z => z.JobId == x.job.JobId)), }; return(View("ListJobs", vm)); }
public ViewResult AddRent() { RentAddRentViewModel model = new RentAddRentViewModel(); model.Cars = _carsRepository.GetFreeCars().ToList(); model.Clients = _clientsRepository.GetAllClients().ToList(); return(View(model)); }
public async Task <ActionResult> ListClients() { var clients = await _clientRepository.GetAllClients(); return(View("ListClients", new ClientListModel() { Clients = _mapper.Map <IEnumerable <ClientModel> >(clients) })); }
public ViewResult AddService(Guid id) { List <Client> facilities = _clientsRepository.GetAllClients().ToList(); Car car = _carsrepository.GetCar(id); AddServiceViewModel viewModel = new AddServiceViewModel() { ServiceFacilities = facilities, Car = car, }; return(View(viewModel)); }
public IActionResult PostOrder([FromBody] OrderEntityModel model) { try { var newOrder = _mapper.Map <OrderEntityModel, Order>(model); CheckDataValidation(newOrder); if (!ModelState.IsValid) { _logger.LogDebug($"bad request from post order made by : {ModelState} "); return(BadRequest(ModelState)); } var client = _clientsRepo .GetClientById(model.ClientId); if (client == null) { ModelState.AddModelError("Errors", "Client is not in Data Base"); return(BadRequest(ModelState)); } string firsName = client.FirstName.ToUpper(); string lastName = client.LastName.ToUpper(); newOrder.OrderNumber = $"{firsName[0]}{lastName.Substring(0, 3)}-{DateTime.Now.Year}{DateTime.Now.Month}{DateTime.Now.Day}{DateTime.Now.Hour}{DateTime.Now.Minute}{DateTime.Now.Second}"; newOrder.Client = _clientsRepo .GetAllClients() .FirstOrDefault(c => c.Id == model.ClientId); _repo.AddOrder(newOrder); if (_repo.SaveAll()) { return(Created($"/api/orders/{newOrder.Id}", _mapper.Map <Order, OrderEntityModel>(newOrder))); } } catch (Exception e) { _logger.LogError($"Failed to post order: {e}"); } return(BadRequest(("Failed to save new order"))); }
public async Task <List <ClientResponseModel> > GetAllClients() { var clients = await _clientsRepository.GetAllClients(); var clientList = new List <ClientResponseModel>(); foreach (var client in clients) { clientList.Add(new ClientResponseModel { Id = client.Id, Name = client.Name, Email = client.Email, Phones = client.Phones, AddedBy = client.AddedBy, AddedOn = client.AddedOn, }); } return(clientList); }
public ActionResult <IEnumerable <Client> > GetClients() { try { var clients = _mapper.Map <IEnumerable <Client>, IEnumerable <ClientEntityModel> >(_repo.GetAllClients()); return(Ok(clients)); } catch (Exception e) { _logger.LogError($"Failed to get clients: {e}"); return(BadRequest(("Failed to get clients"))); } }
public async Task <ActionResult <IEnumerable <ClientDTO> > > Get() { return(Ok(await _sitesRepository.GetAllClients())); }
public ViewResult Index() { var model = _clientsRepository.GetAllClients(); return(View(model)); }
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)); }
public List <Client> GetAllClients() { return(_clientsRepository.GetAllClients()); }