public void Create(AuthorEntity authorEntity) { var newEntity = Clone(authorEntity); newEntity.Id = authorList.Count; authorList.Add(newEntity); }
/// <summary> /// 更新一条记录(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual async Task <bool> UpdateAsync(AuthorEntity entity) { Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "Update Author SET " + "UserID = @UserID," + "Type = @Type," + "Name = @Name," + "IsPassed = @IsPassed," + "IsTop = @IsTop," + "IsElite = @IsElite," + "Hits = @Hits," + "LastUseTime = @LastUseTime," + "TemplateID = @TemplateID," + "AuthorPic = @AuthorPic," + "AuthorIntro = @AuthorIntro," + "Address = @Address," + "Tel = @Tel," + "Fax = @Fax," + "Mail = @Mail," + "Email = @Email," + "ZipCode = @ZipCode," + "HomePage = @HomePage," + "Im = @Im," + "Sex = @Sex," + "BirthDay = @BirthDay," + "Company = @Company," + "Department = @Department" + " WHERE " + "ID = @ID"; return(await Task.Run(() => _DB.ExeSQLResult(strSQL, dict))); }
/// <summary> /// 通过数据读取器生成实体类 /// </summary> /// <param name="rdr"></param> /// <returns></returns> private static AuthorEntity GetEntityFromrdr(NullableDataReader rdr) { AuthorEntity info = new AuthorEntity(); info.ID = rdr.GetInt32("ID"); info.UserID = rdr.GetInt32("UserID"); info.Type = rdr.GetString("Type"); info.Name = rdr.GetString("Name"); info.IsPassed = rdr.GetBoolean("IsPassed"); info.IsTop = rdr.GetBoolean("IsTop"); info.IsElite = rdr.GetBoolean("IsElite"); info.Hits = rdr.GetInt32("Hits"); info.LastUseTime = rdr.GetNullableDateTime("LastUseTime"); info.TemplateID = rdr.GetInt32("TemplateID"); info.AuthorPic = rdr.GetString("AuthorPic"); info.AuthorIntro = rdr.GetString("AuthorIntro"); info.Address = rdr.GetString("Address"); info.Tel = rdr.GetString("Tel"); info.Fax = rdr.GetString("Fax"); info.Mail = rdr.GetString("Mail"); info.Email = rdr.GetString("Email"); info.ZipCode = rdr.GetInt32("ZipCode"); info.HomePage = rdr.GetString("HomePage"); info.Im = rdr.GetString("Im"); info.Sex = rdr.GetInt16("Sex"); info.BirthDay = rdr.GetNullableDateTime("BirthDay"); info.Company = rdr.GetString("Company"); info.Department = rdr.GetString("Department"); return(info); }
/// <summary> /// 把实体类转换成键/值对集合 /// </summary> /// <param name="entity"></param> /// <param name="dict"></param> private static void GetParameters(AuthorEntity entity, Dictionary <string, object> dict) { dict.Add("ID", entity.ID); dict.Add("UserID", entity.UserID); dict.Add("Type", entity.Type); dict.Add("Name", entity.Name); dict.Add("IsPassed", entity.IsPassed); dict.Add("IsTop", entity.IsTop); dict.Add("IsElite", entity.IsElite); dict.Add("Hits", entity.Hits); dict.Add("LastUseTime", entity.LastUseTime); dict.Add("TemplateID", entity.TemplateID); dict.Add("AuthorPic", entity.AuthorPic); dict.Add("AuthorIntro", entity.AuthorIntro); dict.Add("Address", entity.Address); dict.Add("Tel", entity.Tel); dict.Add("Fax", entity.Fax); dict.Add("Mail", entity.Mail); dict.Add("Email", entity.Email); dict.Add("ZipCode", entity.ZipCode); dict.Add("HomePage", entity.HomePage); dict.Add("Im", entity.Im); dict.Add("Sex", entity.Sex); dict.Add("BirthDay", entity.BirthDay); dict.Add("Company", entity.Company); dict.Add("Department", entity.Department); }
public static void ToUpdateEntity(this AuthorUpdateRequest request, ref AuthorEntity author) { if (request == null || author == null) { return; } if (!string.IsNullOrEmpty(request.FirstName)) { author.FirstName = request.FirstName; } if (!string.IsNullOrEmpty(request.LastName)) { author.LastName = request.LastName; } if (!string.IsNullOrEmpty(request.LastName)) { author.MainCategory = request.MainCategory; } if (!string.IsNullOrEmpty(request.LastName)) { author.DateOfBirth = request.DateOfBirth; } }
public async Task <IActionResult> Edit(int id, AuthorEntity authorEntity) { if (id != authorEntity.Id) { return(NotFound()); } if (ModelState.IsValid) { _context.Update(authorEntity); try { await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { if (ex.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, "There is already an author with that name"); } } } return(View(authorEntity)); }
protected async Task Execute(MigrationEncryptionProvider provider) { string databaseName = Guid.NewGuid().ToString(); // Feed database with data. using (var contextFactory = new DatabaseContextFactory(databaseName)) { await using var context = contextFactory.CreateContext <DatabaseContext>(provider.SourceEncryptionProvider); await context.Authors.AddRangeAsync(Authors); await context.SaveChangesAsync(); } // Process data migration using (var contextFactory = new DatabaseContextFactory(databaseName)) { await using var context = contextFactory.CreateContext <DatabaseContext>(provider); await context.MigrateAsync(); } // Assert if the context has been decrypted using (var contextFactory = new DatabaseContextFactory(databaseName)) { await using var context = contextFactory.CreateContext <DatabaseContext>(provider.DestinationEncryptionProvider); IEnumerable <AuthorEntity> authors = await context.Authors.Include(x => x.Books).ToListAsync(); foreach (AuthorEntity author in authors) { AuthorEntity original = Authors.FirstOrDefault(x => x.UniqueId == author.UniqueId); AssertAuthor(original, author); } } }
public static void AddAuthor(AuthorEntity author) { using (var db = new DataContext()) { db.Author.Add(author); db.SaveChanges(); } }
public void Update(PrintingEditionEntity printingEdition, AuthorEntity author = null) { if (author is not null && !printingEdition.Authors.Contains(author)) { printingEdition.Authors.Add(author); } base.Update(printingEdition); }
public void CreateAuthor(AuthorEntity author) { /*var nextId = authors.OrderByDescending(a => a.Id).FirstOrDefault().Id + 1; * author.Id = nextId; * this.authors.Add(author); * return author;*/ var savedAuthor = libraryDBContext.Authors.Add(author); }
public void DeleteAuthor(int delID) { AuthorEntity author = new AuthorEntity(); author.AuthorId = delID; db.Entry(author).State = EntityState.Deleted; db.SaveChanges(); }
public void Update(AuthorEntity authorEntity) { var savedEntity = FindById(authorEntity.Id); savedEntity.Id = authorEntity.Id; savedEntity.FirstName = authorEntity.FirstName; savedEntity.LastName = authorEntity.LastName; savedEntity.Email = authorEntity.Email; }
/// <summary> /// Yazarın banını kaldırır işlem başarılıysa true değer döndürür /// </summary> /// <param name="userId"></param> /// <returns></returns> public Result <bool> SetActiveAuthor(int userId) { AuthorEntity author = _authorRepository.GetById(userId); author.IsActive = true; AuthorEntity updated = _authorRepository.Update(author); return(new Result <bool>(updated.IsActive)); }
/// <summary> /// 增加一条记录,返回新的ID号。需要有一个单一主键,并且开启有标识符属性(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual async Task <int> InsertAsync(AuthorEntity entity) { Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "insert into Author (" + "UserID," + "Type," + "Name," + "IsPassed," + "IsTop," + "IsElite," + "Hits," + "LastUseTime," + "TemplateID," + "AuthorPic," + "AuthorIntro," + "Address," + "Tel," + "Fax," + "Mail," + "Email," + "ZipCode," + "HomePage," + "Im," + "Sex," + "BirthDay," + "Company," + "Department) " + "values(" + "@UserID," + "@Type," + "@Name," + "@IsPassed," + "@IsTop," + "@IsElite," + "@Hits," + "@LastUseTime," + "@TemplateID," + "@AuthorPic," + "@AuthorIntro," + "@Address," + "@Tel," + "@Fax," + "@Mail," + "@Email," + "@ZipCode," + "@HomePage," + "@Im," + "@Sex," + "@BirthDay," + "@Company," + "@Department)"; return(await Task.Run(() => _DB.ReturnID(strSQL, dict))); }
private void ExecuteAesEncryptionTest <TContext>(AesKeySize aesKeyType) where TContext : DatabaseContext { AesKeyInfo encryptionKeyInfo = AesProvider.GenerateKey(aesKeyType); var provider = new AesProvider(encryptionKeyInfo.Key, encryptionKeyInfo.IV, CipherMode.CBC, PaddingMode.Zeros); var author = new AuthorEntity("John", "Doe", 42) { Books = new List <BookEntity>() { new BookEntity("Lorem Ipsum", 300), new BookEntity("Dolor sit amet", 390) } }; string authorEncryptedFirstName = provider.Encrypt(author.FirstName); string authorEncryptedLastName = provider.Encrypt(author.LastName); string firstBookEncryptedName = provider.Encrypt(author.Books.First().Name); string lastBookEncryptedName = provider.Encrypt(author.Books.Last().Name); using (var contextFactory = new DatabaseContextFactory()) { // Save data to an encrypted database context using (var dbContext = contextFactory.CreateContext <TContext>(provider)) { dbContext.Authors.Add(author); dbContext.SaveChanges(); } // Read encrypted data from normal context and compare with encrypted data. using (var dbContext = contextFactory.CreateContext <DatabaseContext>()) { var authorFromDb = dbContext.Authors.Include(x => x.Books).FirstOrDefault(); Assert.NotNull(authorFromDb); Assert.Equal(authorEncryptedFirstName, authorFromDb.FirstName); Assert.Equal(authorEncryptedLastName, authorFromDb.LastName); Assert.NotNull(authorFromDb.Books); Assert.NotEmpty(authorFromDb.Books); Assert.Equal(2, authorFromDb.Books.Count); Assert.Equal(firstBookEncryptedName, authorFromDb.Books.First().Name); Assert.Equal(lastBookEncryptedName, authorFromDb.Books.Last().Name); } // Read decrypted data and compare with original data using (var dbContext = contextFactory.CreateContext <TContext>(provider)) { var authorFromDb = dbContext.Authors.Include(x => x.Books).FirstOrDefault(); Assert.NotNull(authorFromDb); Assert.Equal(author.FirstName, authorFromDb.FirstName); Assert.Equal(author.LastName, authorFromDb.LastName); Assert.NotNull(authorFromDb.Books); Assert.NotEmpty(authorFromDb.Books); Assert.Equal(2, authorFromDb.Books.Count); Assert.Equal(author.Books.First().Name, authorFromDb.Books.First().Name); Assert.Equal(author.Books.Last().Name, authorFromDb.Books.Last().Name); } } }
public static int UpdataAuthor(AuthorEntity author) { var sql = $"UPDATE author SET Name = '{author.Name}',Description='{author.Description}' WHERE Id = '{author.Id}' "; using (var cmd = new MySqlCommand(sql, HyMySqlHelper.MySqlConnection)) { var num = cmd.ExecuteNonQuery(); return(num); } }
private AuthorEntity Clone(AuthorEntity authorEntity) { return(new AuthorEntity { Id = authorEntity.Id, FirstName = authorEntity.FirstName, LastName = authorEntity.LastName, Email = authorEntity.Email }); }
public static void UpdataAuthor(AuthorEntity author) { using (var db = new DataContext()) { AuthorEntity authorEntity = db.Author .Where(b => b.Id.Equals(author.Id)).FirstOrDefault(); authorEntity = author; db.SaveChanges(); } }
public void UpdateAuthor(AuthorEntity author) { /*var authorToUpdate = libraryDBContext.Authors.Single(a => a.Id == author.Id); * authorToUpdate.LastName = author.LastName; * authorToUpdate.Name = author.Name; * authorToUpdate.Nationallity = author.Nationallity; * authorToUpdate.Age = author.Age;*/ libraryDBContext.Authors.Update(author); }
public static AuthorEntity TranslateAuthorContractDataToAuthorEntity(Author authorContract) { var authorEntity = new AuthorEntity(); authorEntity.ID = authorContract.ID; authorEntity.FirstName = authorContract.FirstName; authorEntity.LastName = authorContract.LastName; return(authorEntity); }
private Author AdaptAuthor(AuthorEntity bookEntityAuthor) { return(bookEntityAuthor == null ? null : new Author { Id = bookEntityAuthor.Id, FirstName = bookEntityAuthor.FirstName, LastName = bookEntityAuthor.LastName }); }
public async Task <AuthorEntity> AddAuthorAsync(AuthorEntity newAuthor) { if (logger != null) { logger.LogInformation($"********** {nameof(AddAuthorAsync)}"); } bookStoreContext.Authors.Add(newAuthor); await bookStoreContext.SaveChangesAsync(); return(newAuthor); }
public ActionResult Edit(string id) { var result = _provider.Find(id); AuthorEntity ae = new AuthorEntity(); ae.Name = result.ElementAt(0).Name; ae.Research_area = result.ElementAt(0).Research_area; ae.Institution = result.ElementAt(0).Institution; ae.Author_id = result.ElementAt(0).Author_id; return(View(ae)); }
private static AuthorEntity MySqlRead2Author(MySqlDataReader reader) { var author = new AuthorEntity { Id = reader.GetString("Id"), Name = reader.GetString("Name"), Description = reader.GetString("Description") }; return(author); }
public async Task <AuthorDto> GetAuthorAsync(Guid authorId) { if (authorId == Guid.Empty) { throw new ArgumentNullException(nameof(authorId)); } AuthorEntity author = await _context.Authors.FirstOrDefaultAsync(x => x.Id == authorId); return(author.ToDto()); }
// PUT: api/Author/5 public HttpResponseMessage Put(int id, [FromBody] AuthorEntity entity) { var author = AuthorBLL.UpdateAuthor(id, entity); if (author == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.Created, author)); }
/// <summary> /// Validati Token Id /// </summary> /// <param name="author">Author entity</param> /// <returns>Ok: true, Fail: false</returns> public static bool ValidatiTokenId(AuthorEntity author) { // TODO //AuthorUtility.Author auth = new AuthorUtility.Author(); //bool result = auth.ValidatiTokenId(author.Token, author.PhoneNumber).Result; //return result; return(true); }
public static Author MapToModel(AuthorEntity source) { return(new Author { Id = source.Id, FirstName = source.FirstName, LastName = source.LastName, DateOfBirth = source.DateOfBirth, Books = source.Books?.Select(BookMapper.MapToModel).ToList() }); }
// Author models and entity mappings. public AuthorDetailModel MapAuthorEntityToDetailModel(AuthorEntity authorEntity) { return(new AuthorDetailModel { Id = authorEntity.Id, FirstName = authorEntity.FirstName, LastName = authorEntity.LastName, AboutAuthor = authorEntity.AboutAuthor, Recipes = authorEntity.Recipes == null ? null : authorEntity.Recipes.Select(MapRecipeEntityToListModel).ToList() }); }
public static AuthorEntity MapAuthor(string name) { var author = new AuthorEntity(); var fullName = name.Split(" "); author.Name = fullName.Length > 0 ? fullName[0] : ""; author.Surname = fullName.Length > 1 ? fullName[1] : ""; author.Id = HashGenerator.Generate(name); return(author); }