public async Task <SiteViewModelWithChilds> SaveSite(SiteViewModelWithChilds model)
        {
            Site entity;

            if (model.Id == 0)
            {
                entity           = _deepMapper.Map <Site>(model);
                entity.CreatedAt = DateTime.UtcNow;
                entity           = _siteRepository.Add(entity);
            }
            else
            {
                entity           = _simpleMapper.Map <Site>(model);
                entity.UpdatedAt = DateTime.UtcNow;
                entity           = _siteRepository.Update(entity);
                var modelEndpoints = model.Endpoints.Select(x => x.Id).ToArray();

                var removed = await _endpointRepository.Query()
                              .Where(x => x.SiteId == model.Id && !modelEndpoints.Any(me => me == x.Id)).ToListAsync();

                _endpointRepository.Delete(removed);

                model.Endpoints.ForEach(x => x.SiteId = model.Id);
                var endpoints = _simpleMapper.Map <Endpoint[]>(model.Endpoints);
                endpoints = _endpointRepository.AddOrUpdate(endpoints).ToArray();
            }



            await _uow.CommitAsync();

            var result = _deepMapper.Map <SiteViewModelWithChilds>(entity);

            return(result);
        }
示例#2
0
        public async Task <SiteViewModelWithChilds> SaveSite(SiteViewModelWithChilds model)
        {
            var res = await _configurationService.SaveSite(model);

            await BackgroundJobManager.UpdateWorker(res.Id, _configurationService);

            return(res);
        }