예제 #1
0
        public void Save()
        {
            var dc = new RobotBehaviorsDataContext(SqlConnectionString);

            if (this.Id == 0)
            {
                var robotBehavior = new RobotBehavior();
                robotBehavior.SynAppsId       = this.SynAppsId;
                robotBehavior.SynAppsDeviceId = this.SynAppsDeviceId;
                robotBehavior.Status          = this.Status;
                robotBehavior.ActionType      = this.ActionType;
                robotBehavior.ActionBody      = this.ActionBody;
                robotBehavior.IsSynAppsLinked = this.IsSynAppsLinked;
                robotBehavior.IsDeleted       = this.IsDeleted;
                robotBehavior.CreatedAt       = DateTime.Now;

                dc.RobotBehaviors.InsertOnSubmit(robotBehavior);
                dc.SubmitChanges();

                this.Id        = robotBehavior.Id;
                this.CreatedAt = robotBehavior.CreatedAt;
            }
            else
            {
                var records =
                    from n in dc.RobotBehaviors
                    where n.Id == this.Id
                    select n;

                foreach (var r in records)
                {
                    r.SynAppsId       = this.SynAppsId;
                    r.SynAppsDeviceId = this.SynAppsDeviceId;
                    r.Status          = this.Status;
                    r.ActionType      = this.ActionType;
                    r.ActionBody      = this.ActionBody;
                    r.IsSynAppsLinked = this.IsSynAppsLinked;
                    r.IsDeleted       = this.IsDeleted;
                    r.UpdatedAt       = DateTime.Now;
                }
                dc.SubmitChanges();
            }
        }
 partial void DeleteRobotBehavior(RobotBehavior instance);
 partial void UpdateRobotBehavior(RobotBehavior instance);
 partial void InsertRobotBehavior(RobotBehavior instance);