public int Delete(int?id, Csla.SmartDate modifiedDate)
 {
     using (var entities = new AdventureWorks2014Entities())
     {
         entities.Database.Log += WriteLog;
         var model = entities.ProductSubcategories.SingleOrDefault(b => b.ProductSubcategoryID == id && b.ModifiedDate == modifiedDate.Date);
         entities.ProductSubcategories.Remove(model);
         return(entities.SaveChanges());
     }
 }
 public List <int> RetreiveCollection(int?id = null)
 {
     using (var entities = new AdventureWorks2014Entities())
     {
         entities.Database.Log += WriteLog;
         return(entities.ProductCategories
                .Where(b => b.ProductCategoryID == id || !id.HasValue)
                .Select(b => b.ProductCategoryID)
                .ToList());
     }
 }
 public int Create(string name)
 {
     using (var entities = new AdventureWorks2014Entities())
     {
         entities.Database.Log += WriteLog;
         var model = entities.ProductCategories.Add(new ProductCategory {
             Name = name, rowguid = Guid.NewGuid(), ModifiedDate = DateTime.Now
         });
         entities.SaveChanges();
         return(model.ProductCategoryID);
     }
 }
        public int Read(int?id)
        {
            using (var entities = new AdventureWorks2014Entities())
            {
                entities.Database.Log += WriteLog;
                var model = entities.ProductCategories.SingleOrDefault(b => b.ProductCategoryID == id);
                this.Id           = model.ProductCategoryID;
                this.Name         = model.Name;
                this.RowGuidId    = model.rowguid;
                this.ModifiedDate = model.ModifiedDate;

                return(1);
            }
        }
 public int Update(int?id, string name, Guid rowGuidId, SmartDate modifiedDate)
 {
     using (var entities = new AdventureWorks2014Entities())
     {
         try
         {
             entities.Database.Log += WriteLog;
             var model = entities.ProductCategories.SingleOrDefault(b => b.ProductCategoryID == id);
             model.ModifiedDate = DateTime.Now;
             model.rowguid      = rowGuidId;
             model.Name         = name;
             return(entities.SaveChanges());
         }
         catch (System.Data.Entity.Validation.DbEntityValidationException ex)
         {
             var temp = ex.EntityValidationErrors.Select(b => b.ValidationErrors.Select(c => c.ErrorMessage)).ToList();
             throw;
         }
     }
 }