private static void RecalculateBlogArchive(IRepository<BlogPartArchiveRecord> blogArchiveRepository, IBlogPostService blogPostService, BlogPostPart blogPostPart) { blogArchiveRepository.Flush(); // remove all current blog archive records var blogArchiveRecords = from bar in blogArchiveRepository.Table where bar.BlogPart == blogPostPart.BlogPart.Record select bar; blogArchiveRecords.ToList().ForEach(blogArchiveRepository.Delete); // get all blog posts for the current blog var posts = blogPostService.Get(blogPostPart.BlogPart, VersionOptions.Published); // create a dictionary of all the year/month combinations and their count of posts that are published in this blog var inMemoryBlogArchives = new Dictionary<DateTime, int>(); foreach (var post in posts) { if (!post.Has<CommonPart>()) continue; var commonPart = post.As<CommonPart>(); var key = new DateTime(commonPart.CreatedUtc.Value.Year, commonPart.CreatedUtc.Value.Month, 1); if (inMemoryBlogArchives.ContainsKey(key)) inMemoryBlogArchives[key]++; else inMemoryBlogArchives[key] = 1; } // create the new blog archive records based on the in memory values foreach (KeyValuePair<DateTime, int> item in inMemoryBlogArchives) { blogArchiveRepository.Create(new BlogPartArchiveRecord {BlogPart = blogPostPart.BlogPart.Record, Year = item.Key.Year, Month = item.Key.Month, PostCount = item.Value}); } }
private static void RecalculateTimetableArchive(IRepository<TimetablePartArchiveRecord> TimetableArchiveRepository, ITimetableAppointmentService TimetableAppointmentService, TimetableAppointmentPart TimetableAppointmentPart) { TimetableArchiveRepository.Flush(); // remove all current Timetable archive records var TimetableArchiveRecords = from bar in TimetableArchiveRepository.Table where bar.TimetablePart == TimetableAppointmentPart.TimetablePart.Record select bar; TimetableArchiveRecords.ToList().ForEach(TimetableArchiveRepository.Delete); // get all Timetable appointments for the current Timetable var appointments = TimetableAppointmentService.Get(TimetableAppointmentPart.TimetablePart, VersionOptions.Published); // create a dictionary of all the year/month combinations and their count of appointments that are published in this Timetable var inMemoryTimetableArchives = new Dictionary<DateTime, int>(appointments.Count()); foreach (var appointment in appointments) { if (!appointment.Has<CommonPart>()) continue; var commonPart = appointment.As<CommonPart>(); var key = new DateTime(commonPart.PublishedUtc.Value.Year, commonPart.PublishedUtc.Value.Month, 1); if (inMemoryTimetableArchives.ContainsKey(key)) inMemoryTimetableArchives[key]++; else inMemoryTimetableArchives[key] = 1; } // create the new Timetable archive records based on the in memory values foreach (KeyValuePair<DateTime, int> item in inMemoryTimetableArchives) { TimetableArchiveRepository.Create(new TimetablePartArchiveRecord {TimetablePart = TimetableAppointmentPart.TimetablePart.Record, Year = item.Key.Year, Month = item.Key.Month, AppointmentCount = item.Value}); } }
public void Given_Repository(bool cleanFolders) { if(cleanFolders) DeleteFiles(); serializer = new ItemJsonSerializer(dataPath); repo = new ItemRepository(serializer); repo.DataPath = dataPath; projectItem = repo.Create<Project>() as Project; storyItem = repo.Create<Story>() as Story; scenarioItem = repo.Create<Scenario>() as Scenario; interactionItem = new Interaction(); dataItem = new DataItem(); }
private static void RecalculateBlogArchive(IRepository<BlogArchiveRecord> blogArchiveRepository, IRepository<CommonRecord> commonRepository, BlogPost blogPost) { blogArchiveRepository.Flush(); //INFO: (erikpo) Remove all current blog archive records var blogArchiveRecords = from bar in blogArchiveRepository.Table where bar.Blog == blogPost.Blog.Record select bar; blogArchiveRecords.ToList().ForEach(blogArchiveRepository.Delete); //INFO: (erikpo) Get all blog posts for the current blog var postsQuery = from bpr in commonRepository.Table where bpr.ContentItemRecord.ContentType.Name == BlogPostDriver.ContentType.Name && bpr.Container.Id == blogPost.Blog.Record.Id orderby bpr.PublishedUtc select bpr; //INFO: (erikpo) Create a dictionary of all the year/month combinations and their count of posts that are published in this blog var inMemoryBlogArchives = new Dictionary<DateTime, int>(postsQuery.Count()); foreach (var post in postsQuery) { if (!post.PublishedUtc.HasValue) continue; var key = new DateTime(post.PublishedUtc.Value.Year, post.PublishedUtc.Value.Month, 1); if (inMemoryBlogArchives.ContainsKey(key)) inMemoryBlogArchives[key]++; else inMemoryBlogArchives[key] = 1; } //INFO: (erikpo) Create the new blog archive records based on the in memory values foreach (KeyValuePair<DateTime, int> item in inMemoryBlogArchives) { blogArchiveRepository.Create(new BlogArchiveRecord {Blog = blogPost.Blog.Record, Year = item.Key.Year, Month = item.Key.Month, PostCount = item.Value}); } }
public void Create(客戶銀行資訊 entity) { _客戶銀行資訊Repository.Create(entity); _客戶銀行資訊Repository.SaveChanges(); }
public async Task <ActionResult <Sala> > PostSala(Sala sala) { await _context.Create(sala); return(CreatedAtAction("GetSala", new { id = sala.Id }, sala)); }
public void Add(AccountBook accountbook) { //_dao.AccountBook.Add(accountbook); _accountBookRepository.Create(accountbook); }
public async Task <int> Insert(SocialNetwork socialnetwork) { _socialnetworkRepository.Create(socialnetwork); return(await Context.SaveChangesAsync()); }
public int ContractorCreate(ContractorsDTO contractor) { var createrecord = Contractors.Create(mapper.Map <Contractors>(contractor)); return((int)createrecord.ContractorId); }
public int AddNewUser(User entity) { return(_userRepository.Create(entity)); }
public void StorePushNotification(PushNotificationRecord pushElement) { PushNotificationRecord oldPush = _pushNotificationRepository.Fetch(x => (x.UUIdentifier == pushElement.UUIdentifier || x.Token == pushElement.Token) && x.Produzione == pushElement.Produzione && x.Device == pushElement.Device).FirstOrDefault(); DateTime adesso = DateTime.Now; string oldUUId = ""; if (oldPush != null) // se dispositivo già registrato sovrascrivo lo stesso record { oldUUId = oldPush.UUIdentifier; oldPush.Device = pushElement.Device; oldPush.UUIdentifier = pushElement.UUIdentifier; oldPush.Token = pushElement.Token; oldPush.Validated = pushElement.Validated; oldPush.DataModifica = adesso; oldPush.Produzione = pushElement.Produzione; oldPush.Language = pushElement.Language; // anche se il dispositivo è già esistente, registra host, prefix e machineName dell'ambiente corrente // Rif: https://lasergroup.teamwork.com/index.cfm#tasks/18521520 oldPush.RegistrationUrlHost = _shellSetting.RequestUrlHost ?? ""; oldPush.RegistrationUrlPrefix = _shellSetting.RequestUrlPrefix ?? ""; oldPush.RegistrationMachineName = System.Environment.MachineName ?? ""; oldPush.MobileContactPartRecord_Id = EnsureContactId(oldPush.UUIdentifier); _pushNotificationRepository.Update(oldPush); } else { pushElement.Id = 0; pushElement.DataInserimento = adesso; pushElement.DataModifica = adesso; pushElement.MobileContactPartRecord_Id = EnsureContactId(pushElement.UUIdentifier); // se è un nuovo dispositivo, registra anche host, prefix e machineName dell'ambiente corrente pushElement.RegistrationUrlHost = _shellSetting.RequestUrlHost ?? ""; pushElement.RegistrationUrlPrefix = _shellSetting.RequestUrlPrefix ?? ""; pushElement.RegistrationMachineName = System.Environment.MachineName ?? ""; _pushNotificationRepository.Create(pushElement); } // cerca eventuali record corrispondenti in UserDevice e fa sì che ce ne sia uno solo relativo al nuovo UUIdentifier (quello con l'Id più recente) // eliminando eventualmente i duplicati e i record riferiti al vecchio UUIdentifier; UserDeviceRecord my_disp = null; var elencoNuovi = _userDeviceRecord.Fetch(x => x.UUIdentifier == pushElement.UUIdentifier).OrderByDescending(y => y.Id).ToList(); foreach (var record in elencoNuovi) { if (my_disp == null) { my_disp = record; } else { _userDeviceRecord.Delete(record); } } if (oldPush != null && oldUUId != pushElement.UUIdentifier) { var elencoVecchi = _userDeviceRecord.Fetch(x => x.UUIdentifier == oldUUId).OrderByDescending(y => y.Id).ToList(); foreach (var record in elencoVecchi) { if (my_disp == null) { // aggiorna uno dei record che aveva il vecchio UUIdentifier, quello con l'Id più recente my_disp = record; my_disp.UUIdentifier = pushElement.UUIdentifier; _userDeviceRecord.Update(my_disp); } else { _userDeviceRecord.Delete(record); } } } }
public bool Recored <T>(T obj) where T : class { return(_repository.Create(obj)); }
public Vehicle Create(Vehicle vehicle) { return(_repository.Create(vehicle)); }
public T Create(T entity) { var newEntity = _repository.Create(entity); return(newEntity); }
public Artist PostArtist([FromBody] Artist artist) { artistRepo.Create(artist); return(artist); }
public TimeControl Create(TimeControl entity) { return(_timeControlRepository.Create(entity)); }
public void Create(ProductsDto productsDto) { _repositoryProducts.Create(Mapper.Map <Entity.Products>(productsDto)); _repositoryProducts.Save(); }
public IList <Track> CreateTracks(IList <Track> tracks) { return(_trackRepository.Create(tracks)); }
public async Task <int> Insert(ProductAttribute productAttribute) { _productValueRepository.Create(productAttribute); return(await Context.SaveChangesAsync()); }
public IActionResult Create(Flight flight) { flightRepo.Create(flight); return(RedirectToAction("Details", "Itinerary", new { id = flight.ItineraryId })); }
public async Task <ActionResult <Artist> > PostArtist(Artist Artist) { await _repository.Create(Artist); return(Ok(Artist.ArtistId)); }
public void Create(CategoryViewModel model) { var domain = model.ToDomain(); _categoryRepository.Create(domain); }
public void Update(string feature) { if (_processedFeatures.Contains(feature)) { return; } _processedFeatures.Add(feature); Logger.Information("Updating feature: {0}", feature); // proceed with dependent features first, whatever the module it's in var dependencies = _extensionManager.AvailableFeatures() .Where(f => String.Equals(f.Id, feature, StringComparison.OrdinalIgnoreCase)) .Where(f => f.Dependencies != null) .SelectMany(f => f.Dependencies) .ToList(); foreach (var dependency in dependencies) { Update(dependency); } var migrations = GetDataMigrations(feature); // apply update methods to each migration class for the module foreach (var migration in migrations) { // copy the object for the Linq query var tempMigration = migration; // get current version for this migration var dataMigrationRecord = GetDataMigrationRecord(tempMigration); var current = 0; if (dataMigrationRecord != null) { current = dataMigrationRecord.Version.Value; } try { _transactionManager.RequireNew(); // do we need to call Create() ? if (current == 0) { // try to resolve a Create method var createMethod = GetCreateMethod(migration); if (createMethod != null) { current = (int)createMethod.Invoke(migration, new object[0]); } } var lookupTable = CreateUpgradeLookupTable(migration); while (lookupTable.ContainsKey(current)) { try { Logger.Information("Applying migration for {0} from version {1}", feature, current); current = (int)lookupTable[current].Invoke(migration, new object[0]); } catch (Exception ex) { Logger.Error(ex, "An unexpected error occurred while applying migration on {0} from version {1}", feature, current); throw; } } // if current is 0, it means no upgrade/create method was found or succeeded if (current == 0) { continue; } if (dataMigrationRecord == null) { _dataMigrationRepository.Create(new DataMigrationRecord { Version = current, DataMigrationClass = migration.GetType().FullName }); } else { dataMigrationRecord.Version = current; } _transactionManager.RequireNew(); } catch (Exception e) { Logger.Error(e, "Error while running migration version {0} for {1}", current, feature); _transactionManager.Cancel(); } } }
public void AddAccount(Account account) { _repository.Create(account); }
public void CanAddNewItem() { bool result = _repository.Create(sexTest); Assert.AreEqual(true, result); }
public IEnumerable <Activity> Post([FromBody] Activity Activity) { activityRepo.Create(Activity); return(activityRepo.GetAll()); }
public ActionResult Create(Incident incident) { _repository.Create(incident); return(RedirectToAction("List")); }
public IActionResult OnPostCreate(Book book) { Book = _repository.Create(book); _repository.Add(Book); return(new RedirectToPageResult("Index")); }
public bool RecordSystems(Systems system) { logger.LogError(""); return(repository.Create <Systems>(system)); }
private void RecalculateBlogArchive(IRepository<BlogPartArchiveRecord> blogArchiveRepository, BlogPostPart blogPostPart) { blogArchiveRepository.Flush(); var commonPart = blogPostPart.As<CommonPart>(); if(commonPart == null || !commonPart.CreatedUtc.HasValue) return; // get the time zone for the current request var timeZone = _workContextAccessor.GetContext().CurrentTimeZone; var previousCreatedUtc = _previousCreatedUtc.ContainsKey(blogPostPart) ? _previousCreatedUtc[blogPostPart] : DateTime.MinValue; previousCreatedUtc = TimeZoneInfo.ConvertTimeFromUtc(previousCreatedUtc, timeZone); var previousMonth = previousCreatedUtc.Month; var previousYear = previousCreatedUtc.Year; var newCreatedUtc = commonPart.CreatedUtc; newCreatedUtc = newCreatedUtc.HasValue ? TimeZoneInfo.ConvertTimeFromUtc(newCreatedUtc.Value, timeZone) : newCreatedUtc; var newMonth = newCreatedUtc.HasValue ? newCreatedUtc.Value.Month : 0; var newYear = newCreatedUtc.HasValue ? newCreatedUtc.Value.Year : 0; // if archives are the same there is nothing to do if (previousMonth == newMonth && previousYear == newYear) { return; } // decrement previous archive record var previousArchiveRecord = blogArchiveRepository.Table .Where(x => x.BlogPart == blogPostPart.BlogPart.Record && x.Month == previousMonth && x.Year == previousYear) .FirstOrDefault(); if (previousArchiveRecord != null && previousArchiveRecord.PostCount > 0) { previousArchiveRecord.PostCount--; } // if previous count is now zero, delete the record if (previousArchiveRecord != null && previousArchiveRecord.PostCount == 0) { blogArchiveRepository.Delete(previousArchiveRecord); } // increment new archive record var newArchiveRecord = blogArchiveRepository.Table .Where(x => x.BlogPart == blogPostPart.BlogPart.Record && x.Month == newMonth && x.Year == newYear) .FirstOrDefault(); // if record can't be found create it if (newArchiveRecord == null) { newArchiveRecord = new BlogPartArchiveRecord { BlogPart = blogPostPart.BlogPart.Record, Year = newYear, Month = newMonth, PostCount = 0 }; blogArchiveRepository.Create(newArchiveRecord); } newArchiveRecord.PostCount++; }
/// <summary> /// 账号注册 /// </summary> public async Task <IResultObject> SignUp(SignUpDto dto) { // 验证基础信息 dto.Account = dto.Account.Trim(); dto.Password = dto.Password.Trim(); if (string.IsNullOrWhiteSpace(dto.Account) || string.IsNullOrWhiteSpace(dto.Password)) { return(new ResultObject(1, "账户注册信息均不能为空")); } if (!ValidateHelper.IsUserName(dto.Account)) { return(new ResultObject(2, "账号必须是1-16位字母与数字组合")); } if (!ValidateHelper.IsPassword(dto.Password)) { return(new ResultObject(3, "密码必须是6-16位字母与数字组合")); } var user = new User(); try { await _unitOfWork.BeginAsync(); // 设置账号信息 user.Level = (sbyte)LevelEnum.Beginner; user.Account = dto.Account; user.Password = EncryptHelper.Md5Encrypt(dto.Password); user.IpAddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(); user.SignUpTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); // 判断账户存在 var isExist = await _userRepository.IsUserExist(dto.Account); if (isExist) { return(new ResultObject(4, "此账号已被注册")); } // 创建账号信息 user.Id = await _userRepository.Create(user); // 创建账号额度 await _balanceRepository.Create(new UserBalance { Id = user.Id, Credit = 0, Balance = 0 }, true); // 写入缓存信息 if (!RedisSetUser(user)) { await _unitOfWork.RollbackAsync(); RedisRollBack(user); } else { await _unitOfWork.CommitAsync(); } } catch (Exception ex) { await _unitOfWork.RollbackAsync(); RedisRollBack(user); _logger.LogError("注册账号出错:{0}", ex.ToString()); ExceptionHelper.Throw(ex.Message); } return(new ResultObject(0, user.Id)); }
public bool SaveCryptocurrency(Cryptocurrency cryptocurrency) { return(_cryptocurrencyRepository.Create(cryptocurrency)); }
public void Create(Account data) { // TODO: Exception _repository.Create(data); }
public async Task Create(AddJobDetails addJobDetails) { await _repository.Create(addJobDetails); }
public Guid CreateCustomer(Customer customer) { return(_customerRepository.Create(customer)); }