/// <summary> /// Gets events of all organizations. /// </summary> /// <returns>Collection of EventViewModel</returns> public IEnumerable <EventViewModel> GetAllEvents() { try { var events = ((DbSet <Event>)_unitOfWork.EventRepository.Read()) .Include(e => e.Organization) .Include(i => i.EventImages) .Include(e => e.Organization.BannedOrganization) .Where(e => e.Organization.BannedOrganization == null) .Select(c => new EventViewModel() { Id = c.Id, OrganizationId = c.OrganizationId, OrganizationName = c.Organization.Name, Description = c.Description, CreateDate = c.CreateDate, ImageUrl = AzureStorageConfiguration.GetImageUrl(c.EventImages.Single(r => r.IsMain == true).ImageUrl) }).OrderByDescending(e => e.CreateDate); return(events); } catch (Exception ex) { throw new BusinessLogicException(ex.Message); } }
/// <summary> /// Reads detail information about event by identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns> /// the specified item /// </returns> public EventDetailViewModel ReadById(int id) { try { EventDetailViewModel eventDetailViewModel = new EventDetailViewModel(); var eventDetail = _unitOfWork.EventRepository.Read() .Select(c => new { Id = c.Id, OrganizationId = c.OrganizationId, OrganizationName = c.Organization.Name, Description = c.Description, CreateDate = c.CreateDate, ImageUrl = c.EventImages.Select(i => AzureStorageConfiguration.GetImageUrl(i.ImageUrl)).ToList <string>() }).FirstOrDefault(i => i.Id == id); eventDetailViewModel.Id = eventDetail.Id; eventDetailViewModel.OrganizationId = eventDetail.OrganizationId; eventDetailViewModel.OrganizationName = eventDetail.OrganizationName; eventDetailViewModel.Description = eventDetail.Description; eventDetailViewModel.CreateDate = eventDetail.CreateDate; eventDetailViewModel.ImageUrl = eventDetail.ImageUrl; return(eventDetailViewModel); } catch (Exception ex) { throw new BusinessLogicException(ex.Message); } }
private OrganizationViewModel convertOrganizationToOrganizationViewModel(Organization organization) { return(new OrganizationViewModel { Description = organization.Description, LogoUrl = AzureStorageConfiguration.GetImageUrl(organization.LogoUrl), Name = organization.Name, Id = organization.Id }); }
/// <summary> /// Convert OfferedItemImage To OfferedItemImageViewModel /// </summary> /// <param name="offeredItemImages"></param> /// <returns></returns> private OfferedItemImageViewModel ConvertOfferedItemImageToViewModel(OfferedItemImage offeredItemImages) { return(new OfferedItemImageViewModel() { Id = offeredItemImages.Id, IsMain = offeredItemImages.IsMain, OfferedItemId = offeredItemImages.OfferedItemId, ImageUrl = AzureStorageConfiguration.GetImageUrl(offeredItemImages.ImageUrl) }); }
/// <summary> /// Returns offer item image view models fro offered item image entities /// </summary> /// <param name="imageList"></param> /// <returns></returns> private IEnumerable <OfferedItemImageViewModel> ConvertRequestItemImageModelList(IEnumerable <OfferedItemImage> imageList) { IEnumerable <OfferedItemImageViewModel> images = imageList .Select(image => new OfferedItemImageViewModel { Id = image.Id, IsMain = image.IsMain, OfferedItemId = image.OfferedItemId, ImageUrl = AzureStorageConfiguration.GetImageUrl(image.ImageUrl) }); return(images); }
public IEnumerable <string> GetImagesById(int finOpId) { try { return(_unitOfWork.FinOpImages.Read().ToList() .Where(finOpImg => finOpImg.FinOpId == finOpId) .Select(finOpImages => AzureStorageConfiguration.GetImageUrl(finOpImages.ImageUrl)).ToList()); } catch (Exception ex) { throw new BusinessLogicException(ErrorMessages.CantGetImages, ex); } }
/// <summary> /// Converts list of RequestedItemImage model to RequestedItemImageViewModel /// </summary> /// <param name="imageList">RequestedItemImage models list</param> /// <param name="requestedItemId">Id of requested item</param> /// <returns>List of Requested item image view model</returns> private IEnumerable <RequestedImageViewModel> convertRequestItemImageModelList(IEnumerable <RequestedItemImage> imageList, int requestedItemId) { IEnumerable <RequestedImageViewModel> images = imageList .Select(image => new RequestedImageViewModel { Id = image.Id, IsMain = image.IsMain, RequestedItemId = image.RequestedItemId, ImageUrl = AzureStorageConfiguration.GetImageUrl(image.ImageUrl) }); return(images); }
/// <summary>Convert 'EventImage' to 'ImageViewModel'.</summary> /// <param name="imageList">The collection of images.</param> /// <returns>IEnumerable<ImageViewModel></returns> /// <exception cref="BusinessLogicException"></exception> public IEnumerable <ImageViewModel> ConvertToImageViewModel(IEnumerable <EventImage> imageList) { try { return(imageList.Select(image => new ImageViewModel() { Id = image.Id, ImageUrl = AzureStorageConfiguration.GetImageUrl(image.ImageUrl), IsMain = image.IsMain })); } catch (Exception ex) { throw new BusinessLogicException(ex.Message); } }
/// <summary> /// Gets general information about organization by its id /// </summary> /// <param name="id"> Id of organization </param> /// <returns>OrganizationViewModel</returns> public OrganizationViewModel GetOrganizationById(int id) { var organization = _unitOfWork.OrganizationRepository.Get(id); var result = new OrganizationViewModel { Id = organization.Id, Name = organization.Name, Description = organization.Description, IsBanned = false }; if (!String.IsNullOrEmpty(organization.LogoUrl)) { result.LogoUrl = AzureStorageConfiguration.GetImageUrl(organization.LogoUrl); } return(result); }
public EditLogoViewModel EditLogo(EditLogoViewModel item) { var organization = _unitOfWork.OrganizationRepository.Get(item.OrganizationId); if (organization != null) { var task = _imgManageService.UploadImageAsync(Convert.FromBase64String(item.Base64Code), item.ImageExtension); Task.WhenAll(task); organization.LogoUrl = task.Result; _unitOfWork.SaveChanges(); item.LogoUrl = AzureStorageConfiguration.GetImageUrl(organization.LogoUrl); } else { throw new BusinessLogicException(ErrorMessages.BadRequestMessage); } return(item); }
/// <summary> /// Gets events of all organizations per scrollng. /// </summary> /// <returns>Collection of EventViewModel</returns> public IEnumerable <EventViewModel> GetAllEventsByScroll(int countOfEventsToLoad, int koefToLoadEvent) { try { var events = _unitOfWork.EventRepository.Read() .Select(c => new EventViewModel() { Id = c.Id, OrganizationId = c.OrganizationId, OrganizationName = c.Organization.Name, Description = c.Description, CreateDate = c.CreateDate, ImageUrl = AzureStorageConfiguration.GetImageUrl(c.EventImages.Single(r => r.IsMain == true).ImageUrl) }).OrderByDescending(e => e.CreateDate).ToList(); return(GetPageItems(events, countOfEventsToLoad, koefToLoadEvent)); } catch (Exception ex) { throw new BusinessLogicException(ex.Message); } }