Esempio n. 1
0
        /// <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 void SetEventImage(IEnumerable <ImageViewModel> incomingImages, Event eventItem)
        {
            //images in Db
            List <EventImage> storedImages = _unitOfWork.EventImageRepository.Read().Where(i => i.EventId == eventItem.Id).ToList();

            //new images user set
            List <ImageViewModel> incomeNewImages = incomingImages.Select(i => i).Where(i => !String.IsNullOrEmpty(i.Base64Data)).ToList();

            if (incomeNewImages.Any(i => i.IsMain))
            {
                storedImages.ForEach(i => i.IsMain = false);
            }

            //in case when only main image was changed
            storedImages.ForEach(si => si.IsMain = incomingImages.
                                                   Select(i => i).
                                                   Where(i => i.Id == si.Id).
                                                   FirstOrDefault()
                                                   ?.IsMain ?? si.IsMain);

            //old images stored in Db
            var incomeOldImages      = incomingImages.Select(i => i).Where(i => String.IsNullOrEmpty(i.Base64Data));
            var incomeOldImagesModel = incomeOldImages.Select(i => new EventImage()
            {
                Id       = i.Id,
                IsMain   = i.IsMain,
                ImageUrl = i.ImageUrl
            });

            //old images which we have removed from offerItem.Images
            var uslesImages = storedImages.Where(l2 => incomeOldImagesModel.Select(i2 => AzureStorageConfiguration.GetImageNameFromUrl(i2.ImageUrl)).Contains(l2.ImageUrl) == false).ToList();

            foreach (var stuff in uslesImages)
            {
                _unitOfWork.EventImageRepository.Delete(stuff.Id);
                storedImages.Remove(stuff);
                _imgService.DeleteImageAsync(AzureStorageConfiguration.GetImageNameFromUrl(stuff.ImageUrl));
            }

            //save new images
            var newImages = UploadImagesToStorage(incomeNewImages);

            //InsertImagesInDataBase(newImages, eventItem.Id);
            foreach (var picture in newImages)
            {
                var newImg = _unitOfWork.EventImageRepository.Create(new EventImage()
                {
                    Id       = picture.Id,
                    IsMain   = picture.IsMain,
                    ImageUrl = picture.ImageUrl,
                    EventId  = eventItem.Id
                });
                storedImages.Add(newImg);
            }

            eventItem.EventImages = storedImages;
        }
 private OrganizationViewModel convertOrganizationToOrganizationViewModel(Organization organization)
 {
     return(new OrganizationViewModel
     {
         Description = organization.Description,
         LogoUrl = AzureStorageConfiguration.GetImageUrl(organization.LogoUrl),
         Name = organization.Name,
         Id = organization.Id
     });
 }
Esempio n. 5
0
 /// <summary>
 /// Convert OfferedItemImageViewModele To OfferedItemImage
 /// </summary>
 /// <param name="offeredItemImages"></param>
 /// <returns></returns>
 private OfferedItemImage ConvertFromOfferedItemImageViewModelToModel(OfferedItemImageViewModel offeredItemImages)
 {
     return(new OfferedItemImage()
     {
         Id = offeredItemImages.Id,
         IsMain = offeredItemImages.IsMain,
         OfferedItemId = offeredItemImages.OfferedItemId,
         ImageUrl = AzureStorageConfiguration.GetImageNameFromUrl(offeredItemImages.ImageUrl)
     });
 }
Esempio n. 6
0
 /// <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)
     });
 }
Esempio n. 7
0
 private RequestedItemImage ConvertToRequestedItemImage(RequestedImageViewModel requestedImageVM)
 {
     return(new RequestedItemImage()
     {
         Id = requestedImageVM.Id,
         IsMain = requestedImageVM.IsMain,
         RequestedItemId = requestedImageVM.RequestedItemId,
         ImageUrl = AzureStorageConfiguration.GetImageNameFromUrl(requestedImageVM.ImageUrl)
     });
 }
Esempio n. 8
0
        /// <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);
        }
Esempio n. 9
0
 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);
     }
 }
Esempio n. 10
0
        /// <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);
        }
Esempio n. 11
0
 /// <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);
     }
 }
Esempio n. 12
0
        /// <summary>
        /// Set pictures, received as param for specified offered item id
        /// </summary>
        /// <param name="incomingImages">IEnumerable of offered item image view models</param>
        /// <param name="offerItem">offered item entity</param>
        /// <returns>Offered Item Image View models</returns>
        public void SetOfferedItemPictures(IEnumerable <OfferedItemImageViewModel> incomingImages, OfferedItem offerItem)
        {
            //images in Db
            List <OfferedItemImage> storedImages = offerItem.OfferedItemImages.ToList();

            //new images user set
            List <OfferedItemImageViewModel> incomeNewImages = incomingImages.Select(i => i).Where(i => !String.IsNullOrEmpty(i.Base64Data)).ToList();

            if (incomeNewImages.Any(i => i.IsMain))
            {
                storedImages.ForEach(i => i.IsMain = false);
            }

            //in case when only main image was changed
            storedImages.ForEach(si => si.IsMain = incomingImages.
                                                   Select(i => i).
                                                   Where(i => i.Id == si.Id).
                                                   FirstOrDefault()
                                                   ?.IsMain ?? si.IsMain);

            //old images stored in Db
            var incomeOldImages      = incomingImages.Select(i => i).Where(i => String.IsNullOrEmpty(i.Base64Data));
            var incomeOldImagesModel = ConvertOfferedItemImagesVmToModels(incomeOldImages);

            //old images which we have removed from offerItem.Images
            var uslesImages = storedImages.Where(l2 => !incomeOldImagesModel.Any(l1 => l1.ImageUrl == l2.ImageUrl)).ToList();

            foreach (var stuff in uslesImages)
            {
                _unitOfWork.OfferImagesRepository.Delete(stuff.Id);
                storedImages.Remove(stuff);
                _imgService.DeleteImageAsync(AzureStorageConfiguration.GetImageNameFromUrl(stuff.ImageUrl));
            }

            //save new images
            var newImages = UploadImagesToStorage(incomeNewImages, offerItem.Id);

            foreach (var picture in newImages)
            {
                var newImg = _unitOfWork.OfferImagesRepository.Create(picture);
                storedImages.Add(newImg);
            }

            offerItem.OfferedItemImages = storedImages;
        }
        /// <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);
        }
Esempio n. 15
0
        /// <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);
            }
        }