Ejemplo n.º 1
0
        public CPUdto GetCPUByID(Guid guid)
        {
            CPU    cpu    = CPUs.FindById(guid);
            CPUdto cpudto = mapper.Map <CPU, CPUdto>(cpu);

            return(cpudto);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deletes selected CPU product.
        /// </summary>
        /// <param name="obj"></param>
        private async void ExecDeleteCPUAsync(object obj)
        {
            CPU cpu = (CPU)ProductListView.ProductListUserControl.CPUList.SelectedItem;

            CPUs.Remove(cpu);

            switch (App.DataSource)
            {
            case ConnectionResource.LOCALAPI:
                await new WebServiceManager <CPU>().DeleteAsync(cpu);
                break;

            case ConnectionResource.LOCALMYSQL:
                using (var ctx = new MysqlDbContext(ConnectionResource.LOCALMYSQL))
                {
                    ctx.DbSetCPUs.Attach(cpu);
                    ctx.DbSetCPUs.Remove(cpu);
                    await ctx.SaveChangesAsync();
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 3
0
 public void AddCPU(UInt64 PC)
 {
     CPUs.Add(new CPU()
     {
         PC           = PC,
         GetBus       = SystemBus,
         Instructions = Instructions
     });
 }
Ejemplo n.º 4
0
 internal Laptop(
     CPUs.Cpu cpu,
     IRam ram,
     IEnumerable<HardDriver> hardDrives,
     VideoCard videoCard,
     ILaptopBattery laptopBattery)
     : base(cpu, ram, hardDrives, videoCard)
 {
     this.battery = laptopBattery;
 }
 private int GetCPUIndex(CPU cpu)
 {
     foreach (CPU c in CPUs)
     {
         if (c.Id == cpu.Id)
         {
             return(CPUs.IndexOf(c));
         }
     }
     return(-1);
 }
Ejemplo n.º 6
0
        public string CheckCPU(CPUs model, int systemId)
        {
            string finalMessage = "";

            model.SystemId = systemId;

            if (_uof.CpuRepository.IsSystemCpuExists(systemId, out CPUs cpu))
            {
                //if it exists check the different and update
                if (HardwareInformationHelper
                    .CheckSystemCpuChanges(cpu, model, out string resultMessage))
                {
                    string msg = "اطلاعات پردازنده بروزرسانی شد.";
                    model.CpuId = cpu.CpuId;
                    _uof.CpuRepository.Update(model);
                    if (_recordChanges)
                    {
                        _uof.ActivitiesRepository.Insert(new Activities()
                        {
                            Description = msg, EventDate = DateTime.Now
                        });
                    }
                    finalMessage += resultMessage;
                    finalMessage += $"{msg}<newLine>";
                }
            }
            else
            {
                string msg = "اطلاعات پردازنده ثبت شد.";
                _uof.CpuRepository.Insert(model);
                if (_recordChanges)
                {
                    _uof.ActivitiesRepository.Insert(new Activities()
                    {
                        Description = msg, EventDate = DateTime.Now
                    });
                }
                finalMessage += $"{msg}<newLine>";
            }

            return(finalMessage);
        }
Ejemplo n.º 7
0
        public static bool CheckSystemCpuChanges(CPUs oldCpu, CPUs newCpu, out string resultMessage)
        {
            resultMessage = "";
            bool change = false;

            //Check if cpu is changed
            if (oldCpu.Name != newCpu.Name)
            {
                resultMessage += "پردازنده سیستم تغییر کرده است.<newLine>";
                change         = true;
            }

            //Check if there is any changes in cpu cores
            if (oldCpu.Cores != newCpu.Cores)
            {
                resultMessage += "تغییر در تعداد هسته های پردازنده شناسایی شد.<newLine>";
                change         = true;
            }

            return(change);
        }
        /// <summary>
        /// Removes a product from the cart.
        /// </summary>
        /// <param name="obj"></param>
        public void ExecRemoveFromCart(object obj)
        {
            CartItem cartItem = (CartItem)CartView.CartUC.Cart.SelectedItem;

            cartItem.Product.Stock += cartItem.Quantity;
            Cart.Total             -= cartItem.Price;
            Cart.Items.Remove(cartItem);
            cartItem.Cart = null;

            if (cartItem.Product is CPU)
            {
                CPUs.Add((CPU)cartItem.Product);
            }
            else if (cartItem.Product is GPU)
            {
                GPUs.Add((GPU)cartItem.Product);
            }
            else if (cartItem.Product is Motherboard)
            {
                Motherboards.Add((Motherboard)cartItem.Product);
            }
            else if (cartItem.Product is Memory)
            {
                Rams.Add((Memory)cartItem.Product);
            }
            else if (cartItem.Product is Storage)
            {
                StorageComponents.Add((Storage)cartItem.Product);
            }
            else if (cartItem.Product is PSU)
            {
                PSUs.Add((PSU)cartItem.Product);
            }
            else // Case
            {
                Cases.Add((Case)cartItem.Product);
            }
        }
        /// <summary>
        /// Processes the payment.
        /// Stock of products decreased, customer gets charged.
        /// </summary>
        /// <param name="obj"></param>
        private async void ExecProceedToPaymentAsync(object obj)
        {
            Cart.Customer.Money -= Cart.Total;

            switch (App.DataSource)
            {
            case ConnectionResource.LOCALAPI:
                await new WebServiceManager <Cart>().PostAsync(Cart);
                break;

            case ConnectionResource.LOCALMYSQL:
                using (var ctx = new MysqlDbContext(ConnectionResource.LOCALMYSQL))
                {
                    ctx.Entry(Cart.Customer).State = EntityState.Modified;
                    foreach (var item in Cart.Items)
                    {
                        ctx.Entry(item.Product).State = EntityState.Modified;
                    }
                    ctx.DbSetCarts.Add(Cart);
                    await ctx.SaveChangesAsync();
                }
                break;

            default:
                break;
            }

            foreach (var item in Cart.Items)
            {
                if (item.Product.Stock > 0)
                {
                    if (item.Product is CPU)
                    {
                        CPUs.Add((CPU)item.Product);
                    }
                    else if (item.Product is GPU)
                    {
                        GPUs.Add((GPU)item.Product);
                    }
                    else if (item.Product is Motherboard)
                    {
                        Motherboards.Add((Motherboard)item.Product);
                    }
                    else if (item.Product is Memory)
                    {
                        Rams.Add((Memory)item.Product);
                    }
                    else if (item.Product is Storage)
                    {
                        StorageComponents.Add((Storage)item.Product);
                    }
                    else if (item.Product is PSU)
                    {
                        PSUs.Add((PSU)item.Product);
                    }
                    else // Case
                    {
                        Cases.Add((Case)item.Product);
                    }
                }
            }
            Cart.Items.Clear();
            Cart.Total = 0;
        }
        /// <summary>
        /// Adds the selected product to the cart's items.
        /// </summary>
        /// <param name="obj"></param>
        private void ExecAddToCart(object obj)
        {
            ProductListUserControl productListUC = CartView.CartUC.ProductsUC;
            CartItem cartItem = new CartItem();

            cartItem.Cart     = Cart;
            cartItem.Quantity = 1;

            if (productListUC.CPUList.SelectedIndex != -1) // CPU
            {
                CPU cpu = (CPU)productListUC.CPUList.SelectedItem;
                CPUs.Remove(cpu);
                cartItem.Product = cpu;
                cartItem.Price   = cpu.Price;
            }
            else if (productListUC.GPUList.SelectedIndex != -1) // GPU
            {
                GPU gpu = (GPU)productListUC.GPUList.SelectedItem;
                GPUs.Remove(gpu);
                cartItem.Product = gpu;
                cartItem.Price   = gpu.Price;
            }
            else if (productListUC.MotherboardList.SelectedIndex != -1) // Motherboard
            {
                Motherboard motherboard = (Motherboard)productListUC.MotherboardList.SelectedItem;
                Motherboards.Remove(motherboard);
                cartItem.Product = motherboard;
                cartItem.Price   = motherboard.Price;
            }
            else if (productListUC.MemoryList.SelectedIndex != -1) // Memory
            {
                Memory memory = (Memory)productListUC.MemoryList.SelectedItem;
                Rams.Remove(memory);
                cartItem.Product = memory;
                cartItem.Price   = memory.Price;
            }
            else if (productListUC.StorageList.SelectedIndex != -1) // Storage
            {
                Storage storage = (Storage)productListUC.StorageList.SelectedItem;
                StorageComponents.Remove(storage);
                cartItem.Product = storage;
                cartItem.Price   = storage.Price;
            }
            else if (productListUC.PSUList.SelectedIndex != -1) // PSU
            {
                PSU psu = (PSU)productListUC.PSUList.SelectedItem;
                PSUs.Remove(psu);
                cartItem.Product = psu;
                cartItem.Price   = psu.Price;
            }
            else // Case
            {
                Case pcCase = (Case)productListUC.CaseList.SelectedItem;
                Cases.Remove(pcCase);
                cartItem.Product = pcCase;
                cartItem.Price   = pcCase.Price;
            }

            cartItem.Product.Stock--;
            Cart.Total += cartItem.Price;
            Cart.Items.Add(cartItem);
        }
Ejemplo n.º 11
0
        public void SaveCPU(CPUdto cpudto)
        {
            CPU cpu = mapper.Map <CPUdto, CPU>(cpudto);

            CPUs.Create(cpu);
        }
Ejemplo n.º 12
0
 public IEnumerable <CPUdto> GetCPUs()
 {
     return(mapper.Map <IEnumerable <CPU>, IEnumerable <CPUdto> >(CPUs.Get().ToList()));
 }
Ejemplo n.º 13
0
        public void EditCPU(CPUdto cpudto)
        {
            CPU cpu = mapper.Map <CPUdto, CPU>(cpudto);

            CPUs.Update(cpu);
        }
Ejemplo n.º 14
0
        public void DeleteCPU(Guid guid)
        {
            var cpu = CPUs.FindById(guid);

            CPUs.Delete(cpu);
        }