/// <summary>
 /// Create a new VirtualPageKeyword object.
 /// </summary>
 /// <param name="virtualPageKeywordID">Initial value of the VirtualPageKeywordID property.</param>
 /// <param name="virtualPage_VirtualPageID">Initial value of the VirtualPage_VirtualPageID property.</param>
 /// <param name="pageKeyword">Initial value of the PageKeyword property.</param>
 /// <param name="active">Initial value of the Active property.</param>
 /// <param name="createdBy_UserID">Initial value of the CreatedBy_UserID property.</param>
 /// <param name="createdOn">Initial value of the CreatedOn property.</param>
 /// <param name="modifiedBy_UserID">Initial value of the ModifiedBy_UserID property.</param>
 /// <param name="modifiedOn">Initial value of the ModifiedOn property.</param>
 public static VirtualPageKeyword CreateVirtualPageKeyword(global::System.Int32 virtualPageKeywordID, global::System.Int32 virtualPage_VirtualPageID, global::System.String pageKeyword, global::System.Boolean active, global::System.Int32 createdBy_UserID, global::System.DateTime createdOn, global::System.Int32 modifiedBy_UserID, global::System.DateTime modifiedOn)
 {
     VirtualPageKeyword virtualPageKeyword = new VirtualPageKeyword();
     virtualPageKeyword.VirtualPageKeywordID = virtualPageKeywordID;
     virtualPageKeyword.VirtualPage_VirtualPageID = virtualPage_VirtualPageID;
     virtualPageKeyword.PageKeyword = pageKeyword;
     virtualPageKeyword.Active = active;
     virtualPageKeyword.CreatedBy_UserID = createdBy_UserID;
     virtualPageKeyword.CreatedOn = createdOn;
     virtualPageKeyword.ModifiedBy_UserID = modifiedBy_UserID;
     virtualPageKeyword.ModifiedOn = modifiedOn;
     return virtualPageKeyword;
 }
        public VirtualPageResponse SaveKeywords(VirtualPageRequest request)
        {
            VirtualPageResponse response = new VirtualPageResponse();
            response.VirtualPage = new VirtualPageObject();
            response.VirtualPage.VirtualPageId = request.VirtualPageId;
            response.VirtualPage.Keywords = request.Keywords;

            using (var context = new hamptondwellEntities())
            {
                if (request.VirtualPageId > 0 && string.IsNullOrEmpty(request.Keywords))
                {
                    foreach (
                        VirtualPageKeyword keyword in
                            context.VirtualPageKeywords.Where(
                                k => k.VirtualPage_VirtualPageID == request.VirtualPageId
                                     && k.Active == true))
                    {
                        keyword.Active = false;
                        keyword.ModifiedBy_UserID = request.ModifiedByUserId.Value;
                        keyword.ModifiedOn = DateTime.UtcNow;

                    }
                }
                else
                {
                    List<VirtualPageKeyword> keywordList =
                        (from VirtualPageKeyword keyword in context.VirtualPageKeywords.Where(
                            k => k.VirtualPage_VirtualPageID == request.VirtualPageId
                                 && k.Active == true)
                         select keyword).ToList();

                    foreach (string item in request.Keywords.Split(';'))
                    {
                        if (keywordList.Find(k => k.PageKeyword.ToLower() == item.ToLower()) == null)
                        {
                            if (string.IsNullOrEmpty(item) || item == ";")
                                continue;

                            VirtualPageKeyword newKeyword = new VirtualPageKeyword()
                                                                {
                                                                    Active = true,
                                                                    CreatedOn = DateTime.UtcNow,
                                                                    ModifiedOn = DateTime.UtcNow,
                                                                    CreatedBy_UserID = request.CreatedByUserId.Value,
                                                                    ModifiedBy_UserID =
                                                                        request.ModifiedByUserId.Value,
                                                                    PageKeyword = item.Trim(),
                                                                    VirtualPage_VirtualPageID =
                                                                        request.VirtualPageId
                                                                };
                            context.AddObject("VirtualPageKeywords", newKeyword);

                        }
                    }
                    foreach (
                        VirtualPageKeyword keyword in
                            context.VirtualPageKeywords.Where(
                                k => k.VirtualPage_VirtualPageID == request.VirtualPageId
                                     && k.Active == true))
                    {
                        if (request.Keywords.Split(';').Contains(keyword.PageKeyword) == false)
                        {
                            keyword.Active = false;
                            keyword.ModifiedBy_UserID = request.ModifiedByUserId.Value;
                            keyword.ModifiedOn = DateTime.UtcNow;

                        }
                    }

                }
                context.SaveChanges();
            }

            return response;
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the VirtualPageKeywords EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToVirtualPageKeywords(VirtualPageKeyword virtualPageKeyword)
 {
     base.AddObject("VirtualPageKeywords", virtualPageKeyword);
 }