Пример #1
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TifoPartScreen = await _context.TifoPartScreen.FirstOrDefaultAsync(m => m.Id == id);

            if (TifoPartScreen == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Пример #2
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TifoPartScreen = await _context.TifoPartScreen.FindAsync(id);

            if (TifoPartScreen != null)
            {
                _context.TifoPartScreen.Remove(TifoPartScreen);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Пример #3
0
        public async Task <IActionResult> OnPostSendAsync()
        //public ActionResult OnPostSend()
        {
            var    deviceWindow = new DeviceWindow();
            var    Tifodisplay  = new TifoPartScreen();
            var    devices      = new List <DeviceWindow>();
            string sPostValue0  = "";
            string sPostValue1  = "";
            string sPostValue2  = "";
            string sPostValue3  = "";
            string sPostValue4  = "";

            {
                MemoryStream stream = new MemoryStream();
                Request.Body.CopyTo(stream);
                stream.Position = 0;
                using (StreamReader reader = new StreamReader(stream))
                {
                    string requestBody = reader.ReadToEnd();
                    if (requestBody.Length > 0)
                    {
                        var obj = JsonConvert.DeserializeObject <DeviceWindow>(requestBody);
                        if (obj != null)
                        {
                            sPostValue0  = obj.DeviceId;
                            sPostValue1  = obj.Width;
                            sPostValue2  = obj.Height;
                            sPostValue3  = obj.DevicePixelRatio;
                            sPostValue4  = obj.DotsPerInch;
                            deviceWindow = obj;

                            Tifodisplay.DotsPerPixel         = Convert.ToDecimal(obj.DevicePixelRatio);
                            Tifodisplay.TifoPartScreenHeight = (int)(Convert.ToDecimal(obj.Height) * Tifodisplay.DotsPerPixel);
                            Tifodisplay.TifoPartScreenWidth  = (int)(Convert.ToDecimal(obj.Width) * Tifodisplay.DotsPerPixel);
                            Tifodisplay.DotsPerInch          = Convert.ToInt32(obj.DotsPerInch);
                            Tifodisplay.AbsScreenHeight      = Convert.ToInt32(obj.Height) / Tifodisplay.DotsPerInch * 254 / 10;
                            Tifodisplay.AbsScreenWidth       = Convert.ToInt32(obj.Width) / Tifodisplay.DotsPerInch * 254 / 10;
                            //_context.TifoPartScreen.Add(Tifodisplay);  Flyttat
                            //await _context.SaveChangesAsync();
                        }
                    }
                }



                var devicesroot = Path.Combine(hostingEnvironment.WebRootPath, "devices");

                JsonSerializer serializer = new JsonSerializer();


                serializer.NullValueHandling = NullValueHandling.Ignore;



                using (StreamReader sw1 = new StreamReader(devicesroot + "/devices1.txt"))
                    using (JsonReader reader = new JsonTextReader(sw1))
                    {
                        devices = serializer.Deserialize <List <DeviceWindow> >(reader);
                        if (devices != null)
                        {
                            if (devices.Where(deviceWindowinList => deviceWindowinList.DeviceId == deviceWindow.DeviceId).Any() == false)
                            {
                                var newdeviceWindow1 = new DeviceWindow()
                                {
                                    DeviceId         = deviceWindow.DeviceId,
                                    Width            = deviceWindow.Width,
                                    Height           = deviceWindow.Height,
                                    DevicePixelRatio = deviceWindow.DevicePixelRatio,
                                    DotsPerInch      = deviceWindow.DotsPerInch
                                };

                                devices.Add(newdeviceWindow1);
                                // {"ExpiryDate":new Date(1230375600000),"Price":0}
                                _context.TifoPartScreen.Add(Tifodisplay);
                                await _context.SaveChangesAsync();
                            }
                        }
                        else
                        {
                            var newdeviceWindow1 = new DeviceWindow()
                            {
                                DeviceId         = deviceWindow.DeviceId,
                                Width            = deviceWindow.Width,
                                Height           = deviceWindow.Height,
                                DevicePixelRatio = deviceWindow.DevicePixelRatio,
                                DotsPerInch      = deviceWindow.DotsPerInch
                            };
                            devices = new List <DeviceWindow>
                            {
                                newdeviceWindow1
                            };
                            _context.TifoPartScreen.Add(Tifodisplay);
                            await _context.SaveChangesAsync();
                        }
                    }



                serializer.NullValueHandling = NullValueHandling.Ignore;

                using (StreamWriter sw = new StreamWriter(devicesroot + "/devices1.txt"))
                    using (JsonWriter writer = new JsonTextWriter(sw))
                    {
                        serializer.Serialize(writer, devices);
                        // {"ExpiryDate":new Date(1230375600000),"Price":0}
                    }
            }
            List <string> lstString = new List <string>
            {
                sPostValue0,
                sPostValue1,
                sPostValue2,
                sPostValue3,
                sPostValue4
            };

            return(new JsonResult(lstString));
        }