public static ServiceProviderSpecificResp SelectServiceProviderById(int id) { try { using (var dbCtx = new MSDbContext()) { var server = (from s in dbCtx.Servers join c in dbCtx.Categories on s.CategoryId equals c.Id join sp in dbCtx.ServerPhotos on s.Id equals sp.ServerId into ssp from sp in ssp.DefaultIfEmpty() where s.IsActive && c.IsActive && s.Id == id && (sp.IsPrimary || sp == null) select new { s, c, sp.Photo }).FirstOrDefault(); if (server == null) { return(null); } var photos = (from p in dbCtx.ServerPhotos where p.ServerId == id select p).ToList(); List <string> photoBase64List = new List <string>(); foreach (var photo in photos) { string temp = Convert.ToBase64String(photo.Photo); photoBase64List.Add(temp); } ServiceProviderSpecificResp serviceProvider = new ServiceProviderSpecificResp() { Id = server.s.Id, Name = server.s.Name, Address = server.s.Address, CategoryName = server.c.Name, CategoryId = server.c.Id, Tel = server.s.Tel, PrimaryPhoto = server.Photo != null?Convert.ToBase64String(server.Photo) : null, PhotoList = photoBase64List }; return(serviceProvider); } } catch (Exception e) { var ex = new SelectFromDataBaseException(ExceptionMessage.SelectFromCategoriesServerIdException, e); Logger.Log.Error(ex.Message, ex); throw ex; } }
public static Result <ServiceProviderSpecificResp> GetServiceProvider(int providerId) { Result <ServiceProviderSpecificResp> result = null; try { ServiceProviderSpecificResp temp = DA.Queries.Servers.SelectServiceProviderById(providerId); if (temp != null) { result = new Result <ServiceProviderSpecificResp>(temp, null, true); } else { result = new Result <ServiceProviderSpecificResp>(null, new Error(ErrorMessage.ServiceProviderDoesNotExistError), false); } } catch (Exception e) { Logger.Log.Error(e.Message, e); result = new Result <ServiceProviderSpecificResp>(null, new Error(ErrorMessage.LoadServiceProviderSpecsError), false); } return(result); }