public IHttpActionResult CreateMachine(MachineModel MachineModel)
        {
            // if (!ModelState.IsValid)
            // {
            //     return BadRequest();
            // }

            return(Ok(_MachineManager.CreateMachine(MachineModel)));
        }
示例#2
0
        public IHttpActionResult CreateMachine(MachineModel MachineModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            return(Ok(_MachineManager.CreateMachine(MachineModel)));
        }
        public MachinesModule(IMachineManager machineManager)
            : base("machines")
        {
            this.RequiresAuthentication();

            Get("/", p =>
            {
                return(machineManager.GetMachines());
            });

            Get("/{id:int}", p =>
            {
                return(machineManager.GetMachine((int)p.id));
            });

            Put("/", async p =>
            {
                this.RequiresAdmin();

                return(await machineManager.CreateMachine(this.Bind <Machine>()));
            });

            Post("/", async p =>
            {
                this.RequiresAdmin();

                return(await machineManager.UpdateMachine(this.Bind <Machine>()));
            });

            Delete("/{id:int}", p =>
            {
                this.RequiresAdmin();

                return(machineManager.DeleteMachine((int)p.id));
            });

            Post("/sort", p =>
            {
                this.RequiresAdmin();

                machineManager.SortMachines(this.Bind <List <int> >());
                return(HttpStatusCode.OK);
            });
        }
示例#4
0
        //Treatment of the order depending on the order Type : Create / Add/Temperature
        public string TreatInputOrder(InputOrder newOrder)
        {
            string final;

            //Treating the order depending on the command type
            switch (newOrder.Command.ToLower())
            {
            case "create":
            {
                Machine machine = new Machine()
                {
                    MachineName = newOrder.Param1,
                    MachineId   = newOrder.Param2
                };
                bool result = machineManager.CreateMachine(machine);
                if (result == false)
                {
                    final = "A machine with the same Identifier already exists ! Please Consider using a different Identifier";
                }
                else
                {
                    final = "success";
                }
                break;
            }

            case "add":
            {
                string machineId = newOrder.Param1;
                try
                {
                    int  units = Convert.ToInt32(newOrder.Param2);
                    bool val   = machineManager.AddUnits(units, machineId);
                    if (!val)
                    {
                        final = "Machine not found , please check the machine identifier used";
                    }
                    else
                    {
                        final = "success";
                    }
                }
                catch (Exception ex)
                {
                    final = "please check the add operations parameters ! The last parameter should be integer";
                }

                break;
            }

            case "temperature":
            {
                string machineId = newOrder.Param1;
                try
                {
                    int  temperature = Convert.ToInt32(newOrder.Param2);
                    bool val         = machineManager.SetTemperature(temperature, machineId);
                    if (!val)
                    {
                        final = "Machine not found , please check the machine identifier used";
                    }
                    else
                    {
                        final = "success";
                    }
                }
                catch (Exception ex)
                {
                    final = "please check the add operations parameters ! The last parameter should be integer";
                }
                break;
            }

            default:
            {
                final = "please check the  operations parameters ! Order not recognized";
                break;
            }
            }
            return(final);
        }