public async Task <ActionResult> Detail(int id) { try { var x = await new FailureRepo().GetByIdAsync(id); var data = Mapper.Map <FailureViewModel>(x); data.ClientId = x.ClientId; var client = await NewUserManager().FindByIdAsync(data.ClientId); data.ClientName = client.Name; data.ClientSurname = client.Surname; data.PhotoPath = new PhotoRepo().GetAll(y => y.FailureId == id).Select(y => y.Path).ToList(); var operations = new OperationRepo() .GetAll() .Where(y => y.FailureId == data.FailureId) .OrderByDescending(y => y.CreatedDate) .ToList(); data.Operations.Clear(); foreach (Operation operation in operations) { data.Operations.Add(Mapper.Map <OperationViewModel>(operation)); } var TechnicianRole = NewRoleManager().FindByName("Technician").Users.Select(y => y.UserId).ToList(); for (int i = 0; i < TechnicianRole.Count; i++) { var User = NewUserManager().FindById(TechnicianRole[i]); Technicians.Add(new SelectListItem() { Text = User.Name + " " + User.Surname, Value = User.Id }); } ViewBag.TechnicianList = Technicians; return(View(data)); } catch (Exception ex) { TempData["Model"] = new ErrorViewModel() { Text = $"Bir hata oluştu {ex.Message}", ActionName = "Detail", ControllerName = "Operator", ErrorCode = 500 }; return(RedirectToAction("Error", "Home")); } }
public async Task <ActionResult> Detail(int id) { try { var x = await new FailureRepo().GetByIdAsync(id); var data = Mapper.Map <FailureViewModel>(x); data.PhotoPath = new PhotoRepo().GetAll(y => y.FailureId == id).Select(y => y.Path).ToList(); data.ClientId = x.ClientId; var client = await NewUserManager().FindByIdAsync(data.ClientId); data.ClientName = client.Name; data.ClientSurname = client.Surname; var operations = new OperationRepo() .GetAll() .Where(y => y.FailureId == data.FailureId) .OrderByDescending(y => y.CreatedDate) .ToList(); data.Operations.Clear(); foreach (Operation operation in operations) { data.Operations.Add(Mapper.Map <OperationViewModel>(operation)); } return(View(data)); } catch (Exception ex) { TempData["Model"] = new ErrorViewModel() { Text = $"Bir hata oluştu {ex.Message}", ActionName = "Detail", ControllerName = "Failure", ErrorCode = 500 }; return(RedirectToAction("Error", "Home")); } }
public async Task <ActionResult> Detail(int id) { try { var x = await new FailureRepo().GetByIdAsync(id); var data = Mapper.Map <FailureViewModel>(x); data.PhotoPath = new PhotoRepo().GetAll(y => y.FailureId == id).Select(y => y.Path).ToList(); data.ClientId = x.ClientId; var client = await NewUserManager().FindByIdAsync(data.ClientId); data.ClientName = client.Name; data.ClientSurname = client.Surname; var operations = new OperationRepo() .GetAll() .Where(y => y.FailureId == data.FailureId) .OrderByDescending(y => y.CreatedDate) .ToList(); data.Operations.Clear(); foreach (Operation operation in operations) { data.Operations.Add(Mapper.Map <OperationViewModel>(operation)); } var TechnicianRole = NewRoleManager().FindByName("Technician").Users.Select(y => y.UserId).ToList(); for (int i = 0; i < TechnicianRole.Count; i++) { var distance = 0.0; string distanceString = ""; var technician = NewUserManager().FindById(TechnicianRole[i]); if (technician.Latitude.HasValue && technician.Longitude.HasValue && data.Latitude.HasValue && data.Longitude.HasValue) { var failureCoordinate = new GeoCoordinate(data.Latitude.Value, data.Longitude.Value); var technicianCoordinate = new GeoCoordinate(technician.Latitude.Value, technician.Longitude.Value); distance = failureCoordinate.GetDistanceTo(technicianCoordinate) / 1000; distanceString = $"(~{Convert.ToInt32(distance)} km)"; } if (technician.TechnicianStatus == TechnicianStatuses.Available) { Technicians.Add(new SelectListItem() { Text = technician.Name + " " + technician.Surname + " " + distanceString, Value = technician.Id }); } } ViewBag.TechnicianList = Technicians; return(View(data)); } catch (Exception ex) { TempData["Model"] = new ErrorViewModel() { Text = $"Bir hata oluştu {ex.Message}", ActionName = "Detail", ControllerName = "Operator", ErrorCode = 500 }; return(RedirectToAction("Error", "Home")); } }