Beispiel #1
0
 public ActionResult CreateDetail(Detail detail)
 {
     if (detail.Name != null && detailRepository.GetBy(currentDetail => currentDetail.Name == detail.Name) != null)
     {
         Response.StatusCode = (Int32)HttpStatusCode.NotFound;
         return(null);
     }
     detailRepository.Replace(detailRepository.Create(), detail);
     return(GetDetail());
 }
        public void Create(DetailModel model)
        {
            var detail = new Detail
            {
                Price          = model.Price,
                CarId          = model.CarId,
                ManufacturerId = model.ManufacturerId,
                TypeId         = model.TypeId
            };

            detailRepository.Create(detail);
        }
Beispiel #3
0
        public void Create(DetailModel detailModel)
        {
            var detail = new Detail
            {
                Id             = detailModel.Id,
                CarId          = detailModel.CarId,
                Name           = detailModel.Name,
                Price          = detailModel.Price,
                DetailTypeId   = detailModel.DetailTypeId,
                ManufacturerId = detailModel.ManufacturerId
            };

            detailRepository.Create(detail);
        }
        private ValidResult savesBy(IEnumerable <Detail> details)
        {
            var packageInformation = PackageInformation.CreateInstance(string.Empty);

            packageInformation.Id             = Guid.NewGuid();
            packageInformation.IsReadComplate = true;

            var validResult = new ValidResult();

            foreach (var detail in details)
            {
                detail.Recorder           = HttpContext.User.Claims.FirstOrDefault(p => p.Type == ClaimTypes.Name).Value;
                detail.PackageInformation = packageInformation;
                this.validBy(validResult, detail);
            }

            if (!validResult.IsValid)
            {
                return(validResult);
            }

            try
            {
                foreach (var detail in details)
                {
                    if (detailRepository.Exist(detail.Id))
                    {
                        detailRepository.Update(detail);
                    }
                    else
                    {
                        detailRepository.Create(detail).Wait();
                    }
                }
            }
            catch (Exception exception)
            {
                logger.LogError(JsonConvert.SerializeObject(details));
                throw exception;
            }

            return(validResult);
        }
Beispiel #5
0
        public void Execution(string[] args)
        {
            logger.Debug($"this.localMongoDBOptions.ConnectionString: {this.localMongoDBOptions.ConnectionString}");
            logger.Debug($"this.remoteMongoDBOptions.ConnectionString: {this.remoteMongoDBOptions.ConnectionString}");

            var localAccountingSubjectRepository  = new AccountingSubjectRepository(this.localMongoDBOptions);
            var remoteAccountingSubjectRepository = new AccountingSubjectRepository(this.remoteMongoDBOptions);

            var accountingSubjects = remoteAccountingSubjectRepository.FetchAll().Result;

            logger.Debug($"accountingSubjects.Count(): {accountingSubjects.Count()}");

            localAccountingSubjectRepository.DeleteAll().Wait();
            logger.Debug($"localAccountingSubjectRepository.DeleteAll().Wait();");

            localAccountingSubjectRepository.CreateAll(accountingSubjects).Wait();
            logger.Debug($"localAccountingSubjectRepository.CreateAll(accountingSubjects).Wait();");

            var localAuthorizationRepository  = new AuthorizationRepository(this.localMongoDBOptions);
            var remoteAuthorizationRepository = new AuthorizationRepository(this.remoteMongoDBOptions);

            var authorizations = remoteAuthorizationRepository.FetchAll().Result;

            logger.Debug($"authorizations.Count(): {authorizations.Count()}");

            localAuthorizationRepository.DeleteAll().Wait();
            logger.Debug($"localAuthorizationRepository.DeleteAll().Wait();");

            localAuthorizationRepository.CreateAll(authorizations).Wait();
            logger.Debug($"localAuthorizationRepository.CreateAll(authorizations).Wait();");

            var localBookRepository  = new BookRepository(this.localMongoDBOptions);
            var remoteBookRepository = new BookRepository(this.remoteMongoDBOptions);

            var books = remoteBookRepository.FetchAll().Result;

            logger.Debug($"books.Count(): {books.Count()}");

            if (books.Count() > 0)
            {
                localBookRepository.DeleteAll().Wait();
                logger.Debug($"localBookRepository.DeleteAll().Wait();");

                localBookRepository.CreateAll(books).Wait();
                logger.Debug($"localBookRepository.CreateAll(books).Wait();");
            }

            var localDetailRepository  = new DetailRepository(this.localMongoDBOptions);
            var remoteDetailRepository = new DetailRepository(this.remoteMongoDBOptions);

            var packageInformationIds = localDetailRepository.GetPackageInformationIds();

            logger.Debug($"packageInformationIds.Count(): {packageInformationIds.Count()}");

            var details = remoteDetailRepository.FetchAll(item => !packageInformationIds.Contains(item.PackageInformation.Id)).Result;

            logger.Debug($"details.Count(): {details.Count()}");

            foreach (var detail in details)
            {
                if (localDetailRepository.Exist(detail.Id))
                {
                    localDetailRepository.Update(detail);
                }
                else
                {
                    localDetailRepository.Create(detail).Wait();
                }
            }
            logger.Debug($"localDetailRepository.CreateAll(details).Wait();");
        }