コード例 #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var    item   = JObject.Load(reader);
            object target = null;

            switch (item["Type"].Value <string>()) // this is the property differentiater
            {
            case "1":
                target = new Costumer();
                break;

            case "2":
                target = new Supplyer();
                break;

            case "3":
                target = new Manager();
                break;

            default:
                throw new NotImplementedException();
            }

            serializer.Populate(item.CreateReader(), target);

            return(target);
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Deleted")] Supplyer supplyer)
        {
            if (id != supplyer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(supplyer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SupplyerExists(supplyer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(supplyer));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Deleted")] Supplyer supplyer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(supplyer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(supplyer));
        }
コード例 #4
0
ファイル: UserUI.cs プロジェクト: GoranTurundzov/C_sharp
        public static void SetCarPrice(Supplyer user, Vehicle car)
        {
            int price = 0;

            Console.WriteLine("New Price?");
            while (!int.TryParse(Console.ReadLine(), out price))
            {
                Console.WriteLine("Invalid input (enter the price in number format)");
            }
            Console.WriteLine($"{user.FirstName} set the price for {car.Name} {car.Model} to {price}");
            car.SetPrice(price);
        }
コード例 #5
0
ファイル: UserUI.cs プロジェクト: GoranTurundzov/C_sharp
        public static void EditEmployeesSalary(Manager user, Supplyer employee)
        {
            while (true)
            {
                Console.WriteLine("Pick an action");
                Console.WriteLine("1. Raise");
                int sum = 0;
                Console.WriteLine("2. Lower");
                Console.WriteLine("0 Back");
                switch (Console.ReadLine())
                {
                case "1":

                    while (true)
                    {
                        Console.WriteLine($"Raise {employee.FirstName} salary by how much?");
                        if (int.TryParse(Console.ReadLine(), out sum))
                        {
                            Console.WriteLine(employee.RaiseSalary(user, sum));
                            break;
                        }
                        Console.WriteLine("Wrong Input");
                    }


                    continue;

                case "2":

                    while (true)
                    {
                        Console.WriteLine($"Lower {employee.FirstName} salary by how much?");
                        if (int.TryParse(Console.ReadLine(), out sum))
                        {
                            Console.WriteLine(employee.LowerSalary(user, sum));
                            break;
                        }
                        Console.WriteLine("Wrong Input");
                    }

                    continue;

                case "0":
                    Helper.SlowPrint("Exiting");
                    break;

                default:
                    Console.WriteLine("Wrong Input");
                    continue;
                }
                break;
            }
        }
コード例 #6
0
        public bool AddSupplier(string supplierId, string cvr, string name, Address address, ContactInfo contactInfo)
        {
            bool result = false;

            using (GrainBarrelContext gbc = new GrainBarrelContext())
            {
                Supplyer sup = new Supplyer()
                {
                    SupplierId = supplierId, Cvr = cvr, Name = name, Address = address, ContactInfo = contactInfo
                };
                gbc.Suppliers.Add(sup);
                gbc.SaveChanges();
            }
            result = true;
            return(result);
        }
コード例 #7
0
ファイル: UserUI.cs プロジェクト: GoranTurundzov/C_sharp
        public static void SupplyerPannel(Supplyer user)
        {
            while (true)
            {
                Console.WriteLine("Select: \n 1. Set Car Price \n 2. Get a new car for the shop \n 0. Exit");
                int id = 0;
                switch (Console.ReadLine())
                {
                case "1":
                    Console.Clear();
                    Console.WriteLine(ShopDB.GetCarsForSupplyer());
                    while (true)
                    {
                        Console.WriteLine("Select a car by ID to set a new price");
                        if (!int.TryParse(Console.ReadLine(), out id))
                        {
                            Console.WriteLine("Invalid Selection");
                            continue;
                        }
                        Vehicle car = ShopDB.Vehicles.FirstOrDefault(x => x.Id == id);
                        if (car == null)
                        {
                            Console.WriteLine("No car with that ID exists");
                            continue;
                        }
                        SetCarPrice(user, car);
                        break;
                    }
                    continue;

                case "2":
                    AquireNewCar();
                    continue;

                case "0":
                    Helper.SlowPrint("Exiting menu...");
                    break;

                default:
                    Console.WriteLine("Invalid input");
                    continue;
                }
                break;
            }
        }
コード例 #8
0
        public bool UpdateSupplier(string supplierId, string cvr, string name, Address address, ContactInfo contactInfo)
        {
            bool result = false;

            using (GrainBarrelContext gbc = new GrainBarrelContext())
            {
                var      target = gbc.Suppliers.SingleOrDefault(b => b.SupplierId == supplierId);
                Supplyer sup    = new Supplyer()
                {
                    SupplierId = supplierId, Cvr = cvr, Name = name, Address = address, ContactInfo = contactInfo
                };
                if (target != null)
                {
                    target = sup;
                    gbc.SaveChanges();
                    result = true;
                }
            }
            return(result);
        }
コード例 #9
0
ファイル: App.cs プロジェクト: Ralms/ave-2017-18-sem1-i41n
    public static void Main(string [] args)
    {
        Supplyer <string> sup1 = Funcs.Foo;
        Supplyer <object> sup2 = Funcs.Bar;

        // Incompatible types:
        //    * Expected: () -> object
        //    * Actual:   object -> void
        Supplyer <object> sup3 = Funcs.Zoo; // No overload for 'Zoo' matches delegate 'Supplyer<object>'

        Consumer <object> cons1 = Funcs.Zoo;
        Consumer <object> cons2 = System.Console.WriteLine;

        cons2.Invoke("Invoke println through function reference");

        BiFunction <int, int, int> f = App.Add;

        cons2.Invoke(f.Invoke(5, 3)); // 8
        f = App.Sub;
        cons2.Invoke(f.Invoke(5, 3)); // 2
    }