Exemplo n.º 1
0
        private CreateTeam.Response CreateTeamHandler(CreateTeam command)
        {
            ITracer tracer = platform.Tracer;

            tracer.Write("Siemens-SimaticIT-Trace-Custom", Category.Informational, "Create Team Start...");

            //platform.CallCommand()
            //platform.SendCommand()

            //platform.Principal.Identity.Name



            Dictionary <string, object> dict = new Dictionary <string, object>()
            {
                { "command", "log test" }
            };

            platform.ApplicationLog(12101, dict);

            try
            {
                var entity = platform.Create <ITeam>();
                entity.Name        = command.Team.Name;
                entity.Description = command.Team.Description;
                entity.Number      = command.Team.Number;
                entity.IsActive    = command.IsActive;
                entity.IsLeader    = command.IsLeader;

                PropertyValuesSpecification <ITeam> pv = new PropertyValuesSpecification <ITeam>();
                pv.Add("Name", command.Team.Name);

                var existentity = platform.GetEntity(pv);
                if (existentity == null)
                {
                    platform.Submit(entity);
                }
                else
                {
                    return(new CreateTeam.Response {
                        Error = new ExecutionError(-1010, string.Format("[{0}]已经存在,不允许创建", command.Team.Name))
                    });
                }
                tracer.Write("Siemens-SimaticIT-Trace-Custom", Category.Informational, "Create Team End...");
                return(new CreateTeam.Response {
                    Id = entity.Id
                });
            }
            catch (Exception ex)
            {
                return(new CreateTeam.Response {
                    Error = new ExecutionError(-1010, string.Format("[{0}]创建发生异常,异常信息是:{1}", command.Team.Name, ex.Message))
                });
            }
        }
        private UpdateTeam.Response UpdateTeamHandler(UpdateTeam command)
        {
            ITracer tracer = platform.Tracer;

            tracer.Write("Siemens-SimaticIT-Trace-Custom", Category.Informational, "update Team Start...");
            try
            {
                var entity = platform.GetEntity <ITeam>(command.Id);
                if (entity == null)
                {
                    return(new UpdateTeam.Response {
                        Error = new ExecutionError(-1010, string.Format("[{0}]已经不存在,不允许更新", command.Team.Name))
                    });
                }
                else
                {
                    PropertyValuesSpecification <ITeam> pv = new PropertyValuesSpecification <ITeam>();
                    pv.Add("Name", command.Team.Name);
                    var existentity = platform.GetEntity(pv);
                    if (existentity != null)
                    {
                        if (!command.Id.Equals(entity.Id))
                        {
                            return new UpdateTeam.Response {
                                       Error = new ExecutionError(-1010, string.Format("[{0}]已经有其它记录,不允许更新", command.Team.Name))
                            }
                        }
                        ;
                    }
                    entity.Name        = command.Team.Name;
                    entity.Description = command.Team.Description;
                    entity.Number      = command.Team.Number;
                    entity.IsActive    = command.IsActive;
                    entity.IsLeader    = command.IsLeader;
                }
                platform.Submit(entity);
                tracer.Write("Siemens-SimaticIT-Trace-Custom", Category.Informational, "Update Team End...");
                return(new UpdateTeam.Response {
                });
            }
            catch (Exception ex)
            {
                return(new UpdateTeam.Response {
                    Error = new ExecutionError(-1010, string.Format("[{0}]更新发生异常,异常信息是:{1}", command.Team.Name, ex.Message))
                });
            }
        }