public async Task <ActionResult> Index(MachineDetailPage currentPage, string maid) { var organization = UserManager.GetActiveCustomer(HttpContext); if (organization == null) { return(View("~/Views/Machine/MachineDetail/Index.cshtml", new MachineDetailPageViewModel(currentPage) { Machine = new Machine() })); } var userRoles = await _orgUserRepo.GetUserCustomerRolesAsync(SiteUser.UserName, organization.CustomerNo); var machine = await _machineRepository.GetDetailMachineById(maid); var bookServiceUrl = ContentExtensions.GetPageUnderSettingUrl(x => x.BookServicePage); var model = new MachineDetailPageViewModel(currentPage) { Machine = machine ?? new Machine(), IsHasMachineWRight = userRoles?.Any(r => r.RoleName.Equals(Machine_W)) ?? false, UrlBookService = bookServiceUrl }; var machineOwnerPic = await _machineRepository.GetMachinePicUrl(organization.CustomerId, maid); model.IsHasMachineOwnerPicture = !string.IsNullOrEmpty(machineOwnerPic?.PictureUrl); model.Machine.ImageUrl = machineOwnerPic != null ? machineOwnerPic.PictureUrl : _groMachineService.GetMachineImageUrl(model.Machine.Images); foreach (var doc in model.Machine.Documents) { if (!string.IsNullOrEmpty(doc.Url)) { continue; } var fileExtension = Path.GetExtension(doc.FileName); var fullNameWithExtension = $"{doc.Id}{fileExtension}"; doc.Url = _groMachineService.GetVirtualPath(VirtualPathConfig.DocumentsFolder, fullNameWithExtension); } return(View("~/Views/Machine/MachineDetail/Index.cshtml", model)); }
public async Task <ActionResult> Index(MaskinStartPage currentPage) { var organization = UserManager.GetActiveCustomer(HttpContext); if (organization == null) { return(View("Index", new MaskinStartPageViewModel(currentPage))); } var htmlHelper = new UrlHelper(System.Web.HttpContext.Current.Request.RequestContext); var detailUrl = htmlHelper.ContentUrl(currentPage.MachineDetailPage); var machines = _machineRepository.GetAllMachinesForCustomerId(organization.CustomerNo); #if DEBUG machines = _machineRepository.GetAllMachinesForCustomerId("19036719"); #endif //#if !DEBUG // machines = _machineRepository.GetAllMachinesForCustomerId(organization.CustomerNo); //#endif var machineOwnerPictures = await _machineRepository.FindMachinePictures(organization.CustomerId); if (machines != null) { var machineOwnerPicDic = machineOwnerPictures?.GroupBy(s => s.PictureId).ToDictionary(s => s.Key, v => v.FirstOrDefault()) ?? new Dictionary <string, OrganisationPicture>(); foreach (var machine in machines) { var machineOwnerPic = machineOwnerPicDic.ContainsKey(machine.Id) ? machineOwnerPicDic[machine.Id] : null; //var machineImage = machine.Images != null && machine.Images.Count > 0 // ? $"{machine.Images[0].Id}.jpg" // : string.Empty; //var categoryImage = _machineRepository.GetMachineCategoryImage(machine.Group.Id); //machine.ImageUrl = !string.IsNullOrEmpty(machineOwnerPic?.PictureUrl) ? machineOwnerPic.PictureUrl : // !string.IsNullOrEmpty(machineImage) ? // MachineHelper.GetVirtualPath(VirtualPathConfig.ImageFolder, machineImage) : categoryImage; machine.ImageUrl = !string.IsNullOrEmpty(machineOwnerPic?.PictureUrl) ? machineOwnerPic.PictureUrl : _groMachineService.GetMachineImageUrl(machine.Images); } } var machineListPage = new MaskinStartPageViewModel(currentPage) { DetailMachineUrl = detailUrl, ListMachine = machines ?? new List <Machine>() }; return(View("Index", machineListPage)); }