public async Task <IActionResult> GetProductInformation([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(new Response
                {
                    IsError = true,
                    Status = 400,
                    Message = "Sai dữ liệu đầu vào"
                }));
            }
            if (!flag)
            {
                flag = true;
                NotifyChange n      = new NotifyChange(_hubContext);
                var          listId = _context.Products.Select(p => p.ProductId).ToList();
                listId.ForEach(i =>
                {
                    n.GetStock(i);
                });
            }
            var product = await _context.Products.Include(p => p.ProductImages).Include(p => p.EvaluationQuestions).Where(x => x.ProductId == id && x.Discontinued == false).SingleOrDefaultAsync();

            //product.ProductImages = product.ProductImages.Where(p => p.IsThumbnail == true).ToList();
            if (product == null)
            {
                return(Ok(new Response
                {
                    IsError = true,
                    Status = 404,
                    Message = "Sản phẩm không tồn tại"
                }));
            }
            var   product_map = _mapper.Map <ProductInformationViewModel>(product);
            float star        = 0;
            var   evaluation  = product.EvaluationQuestions.Where(e => e.Rate != null && e.ProductId == product.ProductId).ToList();

            for (int i = 1; i <= 5; i++)
            {
                star += i * evaluation.Where(e => e.Rate == i).Count();
            }
            int totalStar = evaluation.Count();

            if (totalStar > 0)
            {
                star = (float)Math.Round((double)star / totalStar, 1);
            }
            else
            {
                star = 0;
            }

            product_map.NumRate = totalStar;
            product_map.Rate    = star;
            return(Ok(new Response
            {
                Module = product_map,
                Status = 200
            }));
        }
Example #2
0
            public SomeModel()
            {
                Count = NotifyChange.Of(() => _count, x => _count = x);

                Message = NotifyChange.Of <string>();

                DetailedMessage = NotifyChange.Select(() => Message + "-" + Count, Message, Count);
            }
Example #3
0
        public void Given_that_no_validation_condition_was_specified_Then_Error_propetry_should_return_null()
        {
            // Arrange
            var count = NotifyChange.Of(0);

            // Act
            // Assert
            count.Error.Should().BeNull();
        }
Example #4
0
        public void Given_NC_with_no_setter_specified_When_I_assing_any_value_Then_exception_should_be_thrown()
        {
            // Arrange
            var number = new NotifyChange <int>(() => 1);

            // Act
            // Assert
            Assert.Throws <DryToolsException>(() => number.Value = 2)
            .Where(ex => ex.Message.Contains("Setter is not provided, therefore value assignment is not supported"));
        }
Example #5
0
        public void Given_some_invalid_NC_When_I_validate_it_without_error_message_Then_it_should_set_NC_Error_property_to_default_error_message()
        {
            // Arrange
            var counter = NotifyChange.Of(-1);

            // Act
            counter = counter.ValidIf(i => i > 0);

            // Assert
            counter.Error.Should().Be(NotifyChange.Defaults.InvalidError);
        }
Example #6
0
        public void Given_some_invalid_NC_When_I_validate_it_with_error_message_Then_it_should_set_NC_indexer_should_return_the_same_message_as_Error()
        {
            // Arrange
            var counter = NotifyChange.Of(-1);

            // Act
            counter = counter.ValidIf(i => i > 0, "Should be positive");

            // Assert
            counter["hey"].Should().Be(counter.Error);
        }
Example #7
0
        public void Given_some_invalid_NC_When_I_validate_it_with_error_message_Then_it_should_set_NC_Error_property_to_specified_message()
        {
            // Arrange
            var counter = NotifyChange.Of(-1);

            // Act
            counter = counter.ValidIf(i => i > 0, "Should be positive");

            // Assert
            counter.Error.Should().Be("Should be positive");
        }
Example #8
0
        public void Given_null_value_When_I_convert_wrapper_to_string_Then_it_should_not_raise_exception()
        {
            // Arrange
            var obj = NotifyChange.Of <object>(null);

            // Act
            // Assert
            var x = string.Empty;

            Assert.DoesNotThrow(() => x = obj.ToString());
            x.Should().Be("Value: Null");
        }
Example #9
0
        public void Given_valid_source_NC_and_another_NC_with_source_Error_property_When_I_assign_invalid_value_to_source_Then_Error_PC_should_be_raised()
        {
            // Arrange
            var counter         = NotifyChange.Of(1).ValidIf(x => x > 0);
            var validationError = counter.GetNotifyChangeOfProperty(x => x.Error);
            var raised          = false;

            validationError.PropertyChanged += (sender, args) => raised = true;

            // Act
            counter.Value = -1;

            // Assert
            raised.Should().BeTrue();
        }
Example #10
0
        public void Given_I_have_selected_from_two_sources_When_selected_result_not_in_use_anymore_and_GC_Then_selected_result_should_be_collected()
        {
            // Arrange
            var model              = new SomeModel();
            var doubleCount        = NotifyChange.Select(() => model.Count.Value * 2, model.Count);
            var doubleCountWeakRef = new WeakReference(doubleCount);

            // Act
            // ReSharper disable RedundantAssignment
            doubleCount = null;
            // ReSharper restore RedundantAssignment
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            // Assert
            doubleCountWeakRef.IsAlive.Should().BeFalse();
            model.Count.Value.Should().Be(0);
        }
Example #11
0
        public void Given_I_have_selected_from_two_sources_When_selected_result_not_in_use_And_sources_are_changed_Then_no_exception_should_be_raised()
        {
            // Arrange
            var model                  = new SomeModel();
            var detailedMessage        = NotifyChange.Select(() => model.Message.Value + model.Count.Value, model.Count, model.Message);
            var detailedMessageWeakRef = new WeakReference(detailedMessage);

            // Act
            // ReSharper disable RedundantAssignment
            detailedMessage = null;
            // ReSharper restore RedundantAssignment

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            // Assert
            Assert.DoesNotThrow(() =>
            {
                model.Count.Value  += 1;
                model.Message.Value = "hey";
            });
            detailedMessageWeakRef.IsAlive.Should().BeFalse();
        }
Example #12
0
 protected virtual void OnNotifyChange(EventArgs args)
 {
     NotifyChange?.Invoke(this, args);
 }
Example #13
0
 private void FileSystemChanged(FileModel model, WatcherChangeTypes type)
 {
     NotifyChange?.Invoke(new ChangedFileModel(model.Name, model.Path, type));
 }
Example #14
0
 public void UpdatedBack()
 {
     NotifyChange?.Invoke();
 }
        public void Given_NC_with_no_setter_specified_When_I_assing_any_value_Then_exception_should_be_thrown()
        {
            // Arrange
            var number = new NotifyChange<int>(() => 1);

            // Act
            // Assert
            Assert.Throws<DryToolsException>(() => number.Value = 2)
                .Where(ex => ex.Message.Contains("Setter is not provided, therefore value assignment is not supported"));
        }
Example #16
0
        public void Start()
        {
            if (NbxJobTask == null)
            {
                NbxJobTask = Task.Run(() =>
                {
                    IPEndPoint local   = new IPEndPoint(IPAddress.Parse(Ip), 0);
                    IPEndPoint destino = new IPEndPoint(IPAddress.Parse(ServerIp), ServerPort);
                    try
                    {
                        Error = false;
                        using (UdpClient client = new UdpClient(local))
                        {
                            int count = 20;
                            Running   = true;
                            while (Running)
                            {
                                Task.Delay(100).Wait();
                                if (count-- <= 0)
                                {
                                    count = 20;
                                    if (Active)
                                    {
                                        try
                                        {
#if _NBX_NOT_SPLITTED__
                                            Byte[] msg =
                                            {
                                                (Byte)CfgService,       (Byte)RadioService, (Byte)TifxService, (Byte)PresService,
                                                (Byte)0xff,             (Byte)0xff,         (Byte)0xff,        (Byte)0xff,
                                                (Byte)(WebPort & 0xff),
                                                (Byte)(WebPort >> 8)
                                            };
                                            client.Send(msg, msg.Length, destino);
                                            NotifyChange?.Invoke(String.Format("{0}: Sending msg C:{1}, R:{2}, T:{3}, P:{4}", Ip, msg[0], msg[1], msg[2], msg[3]));
#else
                                            if (UlisesNbxItem.Mode == "Mixed")
                                            {
                                                var data = new
                                                {
                                                    Machine         = Environment.MachineName,
                                                    ServerType      = "Mixed",
                                                    GlobalMaster    = "Master",
                                                    RadioService    = RadioService.ToString(),
                                                    CfgService      = CfgService.ToString(),
                                                    PhoneService    = PhoneService.ToString(),
                                                    TifxService     = TifxService.ToString(),
                                                    PresenceService = PresService.ToString(),
                                                    WebPort,
                                                    TimeStamp = DateTime.Now
                                                };
                                                string msg = JsonConvert.SerializeObject(data);
                                                Byte[] bin = Encoding.ASCII.GetBytes(msg);
                                                client.Send(bin, bin.Length, destino);

                                                NotifyChange?.Invoke(String.Format("{0}: Sending msg {1}", Ip, msg));
                                            }
                                            else
                                            {
                                                if (NbxType == NbxTypes.Radio || NbxType == NbxTypes.Ambos)
                                                {
                                                    var data = new
                                                    {
                                                        Machine         = Environment.MachineName,
                                                        ServerType      = "Radio",
                                                        GlobalMaster    = "Master",
                                                        RadioService    = RadioService.ToString(),
                                                        CfgService      = CfgService.ToString(),
                                                        PhoneService    = PhoneService.ToString(),
                                                        TifxService     = TifxService.ToString(),
                                                        PresenceService = PresService.ToString(),
                                                        WebPort,
                                                        TimeStamp = DateTime.Now
                                                    };
                                                    string msg = JsonConvert.SerializeObject(data);
                                                    Byte[] bin = Encoding.ASCII.GetBytes(msg);
                                                    client.Send(bin, bin.Length, destino);

                                                    NotifyChange?.Invoke(String.Format("{0}: Sending msg {1}", Ip, msg));
                                                }

                                                if (NbxType == NbxTypes.Telefonia || NbxType == NbxTypes.Ambos)
                                                {
                                                    var data = new
                                                    {
                                                        Machine         = Environment.MachineName,
                                                        ServerType      = "Phone",
                                                        GlobalMaster    = "Master",
                                                        RadioService    = RadioService.ToString(),
                                                        CfgService      = CfgService.ToString(),
                                                        PhoneService    = PhoneService.ToString(),
                                                        TifxService     = TifxService.ToString(),
                                                        PresenceService = PresService.ToString(),
                                                        WebPort,
                                                        TimeStamp = DateTime.Now
                                                    };
                                                    string msg = JsonConvert.SerializeObject(data);
                                                    Byte[] bin = Encoding.ASCII.GetBytes(msg);
                                                    client.Send(bin, bin.Length, destino);

                                                    NotifyChange?.Invoke(String.Format("{0}: Sending msg {1}", Ip, msg));
                                                }
                                            }
#endif
                                        }
                                        catch (Exception x)
                                        {
                                            _log.Error($"UlisesNbx Exception", x);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Error = true;
                    }
                });
            }
        }