示例#1
0
        public IActionResult SaveContentPage(ContentPageModel model)
        {
            var contentPage = model.Id > 0 ? _contentPageService.Get(model.Id) : new ContentPage();

            if (contentPage == null)
            {
                return(NotFound());
            }
            if (model.Published && (model.SeoMeta?.Slug.IsNullEmptyOrWhiteSpace() ?? true))
            {
                if (model.Id > 0)
                {
                    return(R.Fail.With("error", T("Can't publish page without slug")).Result);
                }
            }
            _modelMapper.Map(model, contentPage, nameof(ContentPage.CreatedOn), nameof(ContentPage.PublishedOn), nameof(ContentPage.UserId));
            if (contentPage.Id == 0)
            {
                contentPage.CreatedOn   = DateTime.UtcNow;
                contentPage.PublishedOn = model.PublishedOn == default(DateTime) ? DateTime.UtcNow : model.PublishedOn;
                contentPage.UserId      = ApplicationEngine.CurrentUser.Id;
            }
            contentPage.UpdatedOn = DateTime.UtcNow;
            contentPage.ParentId  = model.ParentId;
            _contentPageService.InsertOrUpdate(contentPage);

            //update the seometa
            _seoMetaService.UpdateSeoMetaForEntity(contentPage, model.SeoMeta);
            return(R.Success.With("contentPageId", contentPage.Id).Result);
        }
示例#2
0
        protected async Task <IActionResult> GetSingle(int id)
        {
            var key = $"{_cachePrefix}_{id}";

            if (_memoryCache.TryGetValue(key, out TExternalModel mappedEntity))
            {
                if (mappedEntity != null)
                {
                    return(Ok(mappedEntity));
                }

                return(NotFound());
            }

            var entity = await _repository.GetEntityAsync(id);

            var mappedModel = _modelMapper.Map(entity, Url);

            _memoryCache.Set(key, mappedModel, CacheDuration);

            if (mappedModel == null)
            {
                return(NotFound());
            }

            return(Ok(mappedModel));
        }
示例#3
0
        public MapperTreeNode(IModelMapper mapper)
            : base()
        {
            Mapper = mapper;

            FNamed = mapper.Map <INamed>();

            Text            = FNamed.Name;
            Tag             = mapper.Model;
            FNamed.Renamed += Item_Renamed;

            if (mapper.CanMap <IParent>())
            {
                var items = mapper.Map <IParent>();
                if (items.Childs != null)
                {
                    // Keep Nodes and items in sync
                    FSynchronizer         = Nodes.SyncWith(items.Childs, CreateChildNode);
                    FSynchronizer.Synced += synchronizer_Synced;
                }
            }
            if (mapper.CanMap <ISelectable>())
            {
                FSelectable = mapper.Map <ISelectable>();
                Checked     = FSelectable.Selected;
                FSelectable.SelectionChanged += Item_SelectionChanged;
            }
        }
示例#4
0
        /// <summary>
        /// Добавить нового сотрудника
        /// </summary>
        /// <returns></returns>
        private async Task InsertEmployee()
        {
            EmployeeModel employeeModel  = GetDataFromForm();
            Employee      newEmployee    = _modelMapper.Map <Employee>(employeeModel);
            string        departmentName = employeeModel.Department;

            newEmployee.DepartmentId = _departmentDictionary[departmentName];

            int id = await _dbEmployee.Insert(newEmployee);

            employeeModel.Id = id;

            _employeeDictionary.Add(id, employeeModel);

            if (_bindingSource == null)
            {
                _bindingSource = new BindingSource {
                    DataSource = _employeeDictionary.Values
                };
                EmployeeDataGrid.DataSource = _bindingSource;
            }
            else
            {
                _bindingSource.Add(employeeModel);
            }
        }
示例#5
0
        public async Task <IActionResult> TransferDetailsForSender(TransferRequestRequest request)
        {
            _logger.LogInformation($"Getting TransferRequest Details, Transfer Account: {request.AccountId}, TransferRequestId: {request.TransferRequestId}");

            var viewModel = await _modelMapper.Map <TransferRequestForSenderViewModel>(request);

            return(View(viewModel));
        }
        private AvailableAttributeModel GetAttributeModel(AvailableAttribute attribute)
        {
            var model = _modelMapper.Map <AvailableAttributeModel>(attribute);

            model.AttributeValues = attribute.AvailableAttributeValues?
                                    .Select(y => _modelMapper.Map <AvailableAttributeValueModel>(y))
                                    .ToList();
            return(model);
        }
示例#7
0
        public IActionResult VendorsList([FromQuery] VendorSearchModel searchModel)
        {
            var vendors      = _vendorService.GetVendors(out var totalMatches, searchModel.SearchPhrase, searchModel.UserId, searchModel.VendorStatus, searchModel.Current, searchModel.RowCount);
            var vendorModels = vendors.Select(x => _modelMapper.Map <VendorModel>(x)).ToList();

            return(R.Success.With("vendors", vendorModels)
                   .WithGridResponse(totalMatches, searchModel.Current, searchModel.RowCount)
                   .Result);
        }
示例#8
0
        public ConsentModel Create(Consent entity)
        {
            var model = _modelMapper.Map <ConsentModel>(entity);

            if (entity.ConsentGroup != null)
            {
                model.ConsentGroup = _modelMapper.Map <ConsentGroupModel>(entity.ConsentGroup);
            }
            return(model);
        }
示例#9
0
        public IActionResult ManufacturersList(ManufacturerSearchModel searchModel)
        {
            var manufacturers = _manufacturerService.SearchManufacturers(out int totalResults, searchModel.SearchPhrase, searchModel.Current,
                                                                         searchModel.RowCount);

            var manufacturersModel = manufacturers.Select(x => _modelMapper.Map <ManufacturerModel>(x)).ToList();

            return(R.Success.With("manufacturers", manufacturersModel)
                   .WithGridResponse(totalResults, searchModel.Current, searchModel.RowCount)
                   .Result);
        }
        public IActionResult ScheduledTasksList(ScheduledTaskSearchModel searchModel)
        {
            var tasks = _scheduledTaskService.GetScheduledTasks(out int totalMatches, searchModel.SearchPhrase,
                                                                searchModel.EnableStatus, searchModel.Current, searchModel.RowCount);
            var models = tasks.Select(x => _modelMapper.Map <ScheduledTaskModel>(x)).ToList();

            return(R.Success.With("tasks", models)
                   .WithGridResponse(totalMatches, searchModel.Current, searchModel.RowCount)
                   .WithParams(searchModel)
                   .Result);
        }
        public IActionResult DiscountsList([FromQuery] DiscountSearchModel searchModel)
        {
            var discountCoupons = _discountCouponService.SearchDiscountCoupons(searchModel.SearchPhrase,
                                                                               out int totalMatches, searchModel.Current, searchModel.RowCount);

            var discountCouponModels = discountCoupons.Select(x => _modelMapper.Map <DiscountModel>(x)).ToList();

            return(R.Success.With("discounts", discountCouponModels)
                   .WithGridResponse(totalMatches, searchModel.Current, searchModel.RowCount)
                   .Result);
        }
示例#12
0
        public void Map_WhenCallsForComplexModel_ShouldMapCorrectly()
        {
            //arrange
            var source   = InMemoryRepository.GetUserViewModel();
            var expected = InMemoryRepository.GetUser();
            //act
            var actual = _mapper.Map <UserVM, User>(source);

            //assert
            Assert.Equal(expected.ToJson(), actual.ToJson());
        }
示例#13
0
        public IActionResult LogsList(LogSearchModel searchModel)
        {
            var logs = _loggerEntityService.GetLogs(out var totalResults, searchModel.SearchPhrase, searchModel.Current,
                                                    searchModel.RowCount);

            var models = logs.Select(x => _modelMapper.Map <LogModel>(x)).ToList();

            return(R.Success.WithGridResponse(totalResults, searchModel.Current, searchModel.RowCount)
                   .With("logs", models)
                   .WithParams(searchModel)
                   .Result);
        }
        public IActionResult CountriesList(CountrySearchModel searchModel)
        {
            var countries = _countryService.GetCountries(out int totalResults, searchModel.SearchPhrase, searchModel.Current,
                                                         searchModel.RowCount);

            var models = countries.Select(x => _modelMapper.Map <CountryModel>(x)).ToList();

            return(R.Success.WithGridResponse(totalResults, searchModel.Current, searchModel.RowCount)
                   .With("countries", models)
                   .WithParams(searchModel)
                   .Result);
        }
示例#15
0
        public IActionResult TaxesList(TaxSearchModel searchModel)
        {
            var taxes = _taxService.Get(out int totalResults, x => true, x => x.Name, page: searchModel.Current,
                                        count: searchModel.RowCount);

            var models = taxes.Select(x => _modelMapper.Map <TaxModel>(x)).ToList();

            return(R.Success.WithGridResponse(totalResults, searchModel.Current, searchModel.RowCount)
                   .With("taxes", models)
                   .WithParams(searchModel)
                   .Result);
        }
示例#16
0
        public IActionResult SearchTermsList([FromQuery] SearchTermSearchModel searchModel)
        {
            var searchTerms = _searchTermService.Get(out var totalResults,
                                                     x => x.Term.StartsWith(searchModel.SearchPhrase), x => x.Score, RowOrder.Descending,
                                                     searchModel.Current, searchModel.RowCount);

            var models = searchTerms.Select(x => _modelMapper.Map <SearchTermModel>(x)).ToList();

            return(R.Success.With("searchTerms", models)
                   .WithGridResponse(totalResults, searchModel.Current, searchModel.RowCount)
                   .Result);
        }
示例#17
0
        protected virtual async Task <IHttpActionResult> GetSingle(int id)
        {
            var model = await _modelService.GetAsync(id);

            if (model == null)
            {
                return(NotFound());
            }

            var mappedModel = _modelMapper.Map(model, Url);

            return(Ok(mappedModel));
        }
示例#18
0
        public async Task <IActionResult> AddDraftApprenticeship(AddDraftApprenticeshipViewModel model)
        {
            var request = await _modelMapper.Map <AddDraftApprenticeshipRequest>(model);

            request.UserId = User.Upn();

            await _commitmentsApiClient.AddDraftApprenticeship(model.CohortId.Value, request);

            var cohortDetailsUrl = $"{model.ProviderId}/apprentices/{model.CohortReference}/Details";
            var url = _urlHelper.ProviderApprenticeshipServiceLink(cohortDetailsUrl);

            return(Redirect(url));
        }
示例#19
0
        public IActionResult GetSlide(int slideId)
        {
            UiSlider slide = null;

            if (slideId <= 0 || (slide = _uiSliderService.Get(slideId)) == null)
            {
                return(NotFound());
            }
            var model = _modelMapper.Map <UiSliderModel>(slide);

            model.ImageUrl = _mediaAccountant.GetPictureUrl(slide.Media);
            return(R.Success.With("slide", model).Result);
        }
示例#20
0
        public IActionResult StoreEditor(int storeId)
        {
            var store = storeId > 0 ? _storeService.Get(storeId) : new Store();

            if (store == null)
            {
                return(NotFound());
            }
            var storeModel = _modelMapper.Map <StoreModel>(store);

            //we need to use storeObject as response because store is already being passed as a global object
            return(R.Success.With("storeObject", storeModel).WithAvailableStores().Result);
        }
示例#21
0
        public async Task <IActionResult> Get(long apprenticeshipId)
        {
            var query  = new GetApprenticeshipQuery(apprenticeshipId);
            var result = await _mediator.Send(query);

            if (result == null)
            {
                return(NotFound());
            }

            var response = await _modelMapper.Map <GetApprenticeshipResponse>(result);

            return(Ok(response));
        }
示例#22
0
        protected void TestMapperCollectionProperty <TPropertyIn, TPropertyOut>(IModelMapper <TIn, TOut> mapper, Expression <Func <TIn, IEnumerable <TPropertyIn> > > inputSelector, IEnumerable <TPropertyIn> inputValue, Expression <Func <TOut, IEnumerable <TPropertyOut> > > outputSelector, IEnumerable <TPropertyOut> outputValue)
            where TPropertyIn : class
            where TPropertyOut : class
        {
            var inputModel  = NewInputModelEntity(inputSelector, inputValue);
            var outputModel = mapper.Map(inputModel);

            AssertOutputModelCollectionProperty(outputSelector, outputModel, outputValue);

            var nullInputModel  = NewInputModelEntity(inputSelector, null);
            var nullOutputModel = mapper.Map(nullInputModel);

            AssertOutputModelCollectionProperty(outputSelector, nullOutputModel, null);
        }
示例#23
0
        public async Task <Competition> GetCompetitionByLeagueCodeAsync(string leagueCode)
        {
            var root = await _serviceClient.GetRootAsync <CompetitionsRootObject>("competitions");

            var competition =
                root
                .Competitions
                .SingleOrDefault(c =>
                                 leagueCode.Equals(c.Code, StringComparison.InvariantCultureIgnoreCase));

            return
                (competition != null?
                 _mapper.Map <CompetitionDto, Competition>(competition) : null);
        }
示例#24
0
        public IActionResult ConsentGroupsList()
        {
            var consentGroups = _consentGroupService.Get(out int totalResults, x => true, x => x.DisplayOrder);

            var models = consentGroups.Select(x => _modelMapper.Map <ConsentGroupModel>(x)).ToList();

            models.Insert(0, new ConsentGroupModel()
            {
                Name          = T(DefaultGroupName),
                IsSystemGroup = true
            });
            return(R.Success.With("consentGroups", models)
                   .WithGridResponse(totalResults + 1, 1, models.Count)
                   .Result);
        }
        public async Task <IActionResult> AddDraftApprenticeship(ReservationsAddDraftApprenticeshipRequest request)
        {
            var model = await _modelMapper.Map <AddDraftApprenticeshipViewModel>(request);

            await AddLegalEntityAndCoursesToModel(model);

            return(View(model));
        }
示例#26
0
        public async Task <IDraftApprenticeshipViewModel> Map(DraftApprenticeshipRequest source)
        {
            var cohort = await _commitmentsApiClient.GetCohort(source.CohortId);

            if (cohort.WithParty != Party.Provider)
            {
                return(await _modelMapper.Map <ViewDraftApprenticeshipViewModel>(source));
            }

            return(await _modelMapper.Map <IDraftApprenticeshipViewModel>(new EditDraftApprenticeshipRequest
            {
                Cohort = cohort,
                Request = source
            }));
        }
示例#27
0
        public IActionResult Index(int id)
        {
            var contentPage = _contentPageService.Get(id);

            if (contentPage == null || (!contentPage.Published && !CurrentUser.IsAdministrator()))
            {
                return(NotFound());
            }
            var contentPageModel = _modelMapper.Map <ContentPageModel>(contentPage);

            SeoMetaHelper.SetSeoData(contentPageModel.Name);
            var r = R.Success.With("contentPage", contentPageModel).With("contentPageId", contentPage.Id)
                    .With("preview", !contentPage.Published);

            if (!contentPage.Template.IsNullEmptyOrWhiteSpace())
            {
                //get the template
                var template = ApplicationEngine.ActiveTheme.GetTemplatePath(contentPage.Template);
                if (!template.IsNullEmptyOrWhiteSpace())
                {
                    r.WithView(template);
                }
            }
            return(r.Result);
        }
        public CurrencyModel Create(Currency entity)
        {
            var model = _modelMapper.Map <CurrencyModel>(entity);

            model.FlagUrl = ApplicationEngine.MapUrl($"~/common/flags/{entity.Flag}");
            return(model);
        }
示例#29
0
        public IActionResult UploadProfilePicture(MediaUploadModel mediaModel)
        {
            if (!_userSettings.AreProfilePicturesEnabled)
            {
                return(NotFound());
            }

            var mediaFile = mediaModel.MediaFile;

            if (mediaFile == null || mediaFile.Length == 0)
            {
                return(R.Fail.Result);
            }

            var media = _mediaAccountant.GetMediaInstance(mediaFile, 0);

            //save it
            _mediaService.Insert(media);
            _userService.Update(new { ProfilePictureId = media.Id }, x => x.Id == CurrentUser.Id, null);

            var model = _modelMapper.Map <MediaModel>(media);

            model.ThumbnailUrl = _mediaAccountant.GetPictureUrl(media, ApplicationEngine.ActiveTheme.UserProfileImageSize, true);
            model.ImageUrl     = _mediaAccountant.GetPictureUrl(media);
            return(R.Success.With("media", model).Result);
        }
示例#30
0
        public override void Reload()
        {
            FTreeView.BeginUpdate();

            if (FRootMapper != null)
            {
                FRootMapper.Dispose();
            }

            FRootMapper = new ModelMapper(Input, Registry);

            if (ShowRoot)
            {
                var rootNode = new MapperTreeNode(FRootMapper);
                rootNode.Expand();
                FTreeView.Nodes.Add(rootNode);
            }
            else
            {
                var items = FRootMapper.Map <IParent>();
                if (FSynchronizer != null)
                {
                    FSynchronizer.Dispose();
                }
                FSynchronizer = FTreeView.Nodes.SyncWith(items.Childs, item => new MapperTreeNode(FRootMapper.CreateChildMapper(item)));
            }

            FTreeView.EndUpdate();
        }