public int CreateNewAuthority(Authority authority) { using (DobbermanEntities context = new DobbermanEntities()) { // find out if authority already exists by its name AuthorityEntity validateAuthority = (from p in context.Authorities where p.Name == authority.Name select p).FirstOrDefault(); if (!(validateAuthority == null)) return validateAuthority.AuthorityId; AuthorityEntity authorityEntity = new AuthorityEntity() { Name = authority.Name, CategoryId = authority.CategoryId, FacebookPage = authority.FacebookPage, AccumulatedScore = 0, Score = 50, }; context.AddToAuthorities(authorityEntity); context.SaveChanges(); return authorityEntity.AuthorityId; } }
private Authority TranslateAuthorityEntityToAuthority(AuthorityEntity authorityEntity) { Authority authority = new Authority() { AuthorityId = authorityEntity.AuthorityId, Name = authorityEntity.Name, FacebookPage = authorityEntity.FacebookPage, Score = authorityEntity.Score, Logo = authorityEntity.Logo, CategoryId = authorityEntity.CategoryId, Category = TranslateCategoryEntityToCategory(authorityEntity.Category), }; return authority; }
/// <summary> /// Create a new AuthorityEntity object. /// </summary> /// <param name="authorityId">Initial value of the AuthorityId property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="facebookPage">Initial value of the FacebookPage property.</param> /// <param name="categoryId">Initial value of the CategoryId property.</param> public static AuthorityEntity CreateAuthorityEntity(global::System.Int32 authorityId, global::System.String name, global::System.String facebookPage, global::System.Int32 categoryId) { AuthorityEntity authorityEntity = new AuthorityEntity(); authorityEntity.AuthorityId = authorityId; authorityEntity.Name = name; authorityEntity.FacebookPage = facebookPage; authorityEntity.CategoryId = categoryId; return authorityEntity; }
/// <summary> /// Deprecated Method for adding a new object to the Authorities EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToAuthorities(AuthorityEntity authorityEntity) { base.AddObject("Authorities", authorityEntity); }