예제 #1
0
        /// <summary>
        /// Gets images by requested item id
        /// </summary>
        /// <param name="imagesList">List of images</param>
        /// <param name="requestedItemId">Id of requested item</param>
        private IEnumerable <RequestedItemImage> UploadImagesToStorage(IEnumerable <RequestedImageViewModel> imagesList,
                                                                       int requestedItemId)
        {
            Dictionary <RequestedItemImage, Task <string> > imageTastDictionary = new Dictionary <RequestedItemImage, Task <string> >();

            foreach (var item in imagesList)
            {
                var newImage = new RequestedItemImage()
                {
                    IsMain          = item.IsMain,
                    RequestedItemId = requestedItemId
                };

                var t = _imgService.UploadImageAsync(Convert.FromBase64String(item.Base64Data), item.ImageExtension);
                imageTastDictionary.Add(newImage, t);
            }
            Task.WhenAll(imageTastDictionary.Values);

            foreach (var element in imageTastDictionary)
            {
                element.Key.ImageUrl = element.Value.Result;
            }

            return(imageTastDictionary.Keys);
        }
        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);
        }
예제 #3
0
        public ICollection <FinOpImage> UploadImagesToStorage(IEnumerable <FinOpImageViewModel> images)
        {
            Dictionary <FinOpImage, Task <string> > imageTastDictionary = new Dictionary <FinOpImage, Task <string> >();

            foreach (var item in images)
            {
                var newImage = new FinOpImage();

                var t = _imgService.UploadImageAsync(Convert.FromBase64String(item.Base64Data), item.imageExtension);
                imageTastDictionary.Add(newImage, t);
            }
            Task.WhenAll(imageTastDictionary.Values);

            foreach (var element in imageTastDictionary)
            {
                element.Key.ImageUrl = element.Value.Result;
            }

            return(imageTastDictionary.Keys);
        }
        /// <summary>
        /// Registers new organization
        /// </summary>
        /// <param name="item"> Item to register </param>
        /// <returns>Registered item</returns>
        public OrganizationRegistrationViewModel RegisterOrganization(OrganizationRegistrationViewModel item)
        {
            var checkOrganization = _unitOfWork.OrganizationRepository.Read().Where(o => o.Name == item.Name).FirstOrDefault();

            if (checkOrganization == null)
            {
                var user = _unitOfWork.UsersRepository.GetUser(item.AdministratorLogin);
                if (user != null)
                {
                    var role            = _unitOfWork.RoleRepository.Read().Where(r => r.Name == "admin").FirstOrDefault();
                    var checkMembership = _unitOfWork.MembershipRepository.Read().Where(m => (m.UserId == user.Id) && (m.RoleId == role.Id)).FirstOrDefault();
                    if (checkMembership == null)
                    {
                        var t = _imgManageService.UploadImageAsync(Convert.FromBase64String(item.LogoBase64Code), item.LogoImageExtension);
                        Task.WhenAll(t);
                        var organization = new Organization {
                            Name = item.Name, Description = item.Description, LogoUrl = t.Result
                        };

                        _unitOfWork.OrganizationRepository.Create(organization);

                        var membership = new Membership {
                            UserId = user.Id, OrgId = organization.Id, RoleId = role.Id
                        };
                        _unitOfWork.MembershipRepository.Create(membership);

                        var address = new Address {
                            City = item.City, Street = item.Street, Country = item.Country, Building = item.House
                        };
                        _unitOfWork.AddressRepository.Create(address);

                        var orgAddres = new OrgAddress {
                            OrgId = organization.Id, AddressId = address.Id
                        };
                        _unitOfWork.OrganizationAddressRepository.Create(orgAddres);
                        organization.OrgAddresses.Add(orgAddres);

                        var interval = new AutoImportIntervals {
                            OrgId = organization.Id, Interval = Constants.DefaultImportInterval, LastUpdateDate = DateTime.Now
                        };
                        _unitOfWork.ImportIntervalRepository.Create(interval);
                        _unitOfWork.SaveChanges();

                        var result = new OrganizationRegistrationViewModel
                        {
                            Name = organization.Name,
                            AdministratorLogin = item.AdministratorLogin,
                            City        = address.City,
                            Country     = address.Country,
                            Street      = address.Street,
                            Description = organization.Description,
                            House       = address.Building
                        };
                        return(result);
                    }
                    else
                    {
                        item.UserError = "Цей користувач вже адмініструє організацію";
                        return(item);
                    }
                }
                item.UserError = "Користувача з таким логіном не зареєстровано";
                return(item);
            }
            item.NameError = "Організація з такою назвою вже існує";
            return(item);
        }