public List <Draw> ReadFile(Entities.Type type) { string path = string.Empty; if (type == Entities.Type.Drawn) { path = config.GetSection("FilePathDrawn").Value; } else if (type == Entities.Type.Generated) { path = config.GetSection("FilePathGenerated").Value; } if (!File.Exists(path)) { Console.WriteLine("File doesn't exist."); return(null); } string json = File.ReadAllText(path); if (string.IsNullOrEmpty(json)) { Console.WriteLine("File exists but it's empty."); return(null); } List <Draw> draws = JsonSerializer.Deserialize <List <Draw> >(json); return(draws); }
public JsonResult Pay(int drugID, int quantity, double discount, Entities.Type compensationType, Guid compensationTypeID) { var drug = ResolveDrug(drugID); if (drug == null) { return(new JsonResult(new { message = $"drug with {drugID} unrecognized." })); } var compensation = ResolveCompensation(compensationTypeID); if (compensation == null) { return(new JsonResult(new { message = $"unrecognized {compensationTypeID} as unique identifier." })); } if (!ResolveCompensationType(compensation, compensationType)) { return(new JsonResult(new { message = $"compensationTypeID: {compensationTypeID} does not match with compensationTypeName." })); } var payableSum = _compensationTypeCalculators.First(c => c.Type == compensationType).Calculate(quantity, drug.RetailPrice, drug.BasicCompensationPrice, drug.CompensationPercent, discount); SaveCompensationRecord(new CompensationRecord { CompensationType = compensation, CreateTime = DateTime.Now, Drug = drug, PayableSum = payableSum }); return(new JsonResult(new { payableSum })); }
public List <Draw> UpdateFile(List <Draw> draws, Draw lastDraw, Entities.Type type) { draws.Add(lastDraw); SaveFile(draws, type); Console.WriteLine("Past draws list updated."); return(draws); }
public void SaveFile(List <Draw> draws, Entities.Type type) { string json = JsonSerializer.Serialize(draws); if (type == Entities.Type.Drawn) { File.WriteAllText(config.GetSection("FilePathDrawn").Value, json); } else if (type == Entities.Type.Generated) { File.WriteAllText(config.GetSection("FilePathGenerated").Value, json); } Console.WriteLine("Past draws list saved."); }
/// <summary> /// Method that will Update the Type passed in the parameters to the database /// </summary> /// <param name="type">Object Type to Update</param> public void Update(Entities.Type type) { _context.Types.Update(type); _context.SaveChanges(); }
/// <summary> /// Method to Add the Type passed in the parameters to the database /// </summary> /// <param name="type">Object Type to Add</param> public void Add(Entities.Type type) { _context.Types.Add(type); _context.SaveChanges(); }
public SpecialFund() { Type = Entities.Type.SpecialFund; }
public HealthInsurance() { Type = Entities.Type.HealthInsurance; }
protected override void Seed(NokProjectX.Wpf.Context.YumiContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // var pcs = new Entities.Type { Name = "pcs" }; var ft = new Entities.Type { Name = "ft" }; context.Types.AddOrUpdate(c => c.Name, pcs, ft ); var product1 = new Product() { Name = "Tarpaulin", Description = "Standard", Price = 10.0d, CodeString = "TARP", CodeNumber = 1000001, Stock = 100, Type = ft, }; var product2 = new Product() { Name = "Tarpaulin", Description = "Regular", Price = 15.0d, CodeString = "TARP", CodeNumber = 1000002, Stock = 100, Type = ft, }; var product3 = new Product() { Name = "Tracing Paper 20 x 30", Description = "Lines", Price = 90.0d, CodeString = "TRAC", CodeNumber = 1000003, Stock = 100, Type = pcs, }; var product4 = new Product() { Name = "Tracing Paper 24 x 34", Description = "Graphics", Price = 120.0d, CodeString = "TRAC", CodeNumber = 1000004, Stock = 100, Type = pcs, }; context.Products.AddOrUpdate(c => c.CodeNumber, product1, product2, product3, product4 ); }
public Government() { Type = Entities.Type.Government; }
public static void InitializeDatabase(EntityContext entityContext) { entityContext.Database.EnsureCreated(); var types = new List <Entities.Type> { new Entities.Type() { Brand = "BMW", Model = "x5" }, new Entities.Type() { Brand = "Ford", Model = "Fiesta" }, new Entities.Type() { Brand = "MiniCooper", Model = "D" }, new Entities.Type() { Brand = "Audi", Model = "A8" }, }; var owners = new List <Owner>(); for (var i = 0; i < 10; i++) { owners.Add(new Owner { FirstName = $"First Name {i}", LastName = $"Last Name {i}" }); } var cars = new List <Car>(); for (var i = 0; i < 10; i++) { Entities.Type type = types[0]; String color = "Geel"; if (i % 4 == 0) { type = types[1]; color = "Rood"; } else if (i % 3 == 0) { type = types[2]; color = "Blauw"; } else if (i % 2 == 0) { type = types[3]; color = "Groen"; } cars.Add(new Car { Plate = $"DEZ46{i}", Owner = owners[i], Type = type, PurchaseDate = DateTime.Now.AddYears(-1).AddDays(i), Color = color }); } entityContext.Type.AddRange(types); entityContext.Owners.AddRange(owners); entityContext.Cars.AddRange(cars); entityContext.SaveChanges(); }
private bool ResolveCompensationType(Compensation compensation, Entities.Type type) { return(compensation.Type == type); }