public async Task <IActionResult> PutCatBreed(long id, CatBreed catBreed) { if (id != catBreed.Id) { return(BadRequest()); } _context.Entry(catBreed).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CatBreedExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
} // end of InitializeGUI() /// <summary> /// Make a Cat! /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnMakeACat_Click(object sender, EventArgs e) { // Validate the Input if (!ValidateInput()) { MessageBox.Show("Please Enter Cat Details", "Error"); return; } // Assemble the Cat Attributes from the Form string name = txtName.Text; int age = (int)numAge.Value; CatBreed breed = (CatBreed)Enum.Parse(typeof(CatBreed), cmbBreed.Text); GenderType gender = (GenderType)Enum.Parse(typeof(GenderType), cmbGender.Text); // Make a Proxy to the Service MakeACatServiceClient proxy = new MakeACatServiceClient(); // Call the Service Cat cat = proxy.MakeACat(name, breed, gender, age); // Add to the Master Cat List mycats.Add(cat); // Update the GUI UpdateGUI(); } // end of method
public Cat(string _name, int _age, float _happiness, CatBreed _catBreed) { name = _name; age = _age; happiness = _happiness; breed = _catBreed.ToString(); }
public async Task <List <CatBreed> > GetTemperamentCatBreeds(int id) { var catBreedTemperaments = await _ctx.CatBreedTemperaments .Where(t => t.TemperamentId == id) .ToListAsync(); var catBreeds = await _ctx.CatBreeds .Include(c => c.Origin) .Include(c => c.Weight) .Include(e => e.CatBreedTemperaments) .ThenInclude(e => e.Temperament) .ToListAsync(); var catBreed = new CatBreed(); var temperamentCatBreeds = new List <CatBreed>(); foreach (var cbt in catBreedTemperaments) { catBreed = catBreeds.Where(c => c.Id == cbt.CatBreedId).FirstOrDefault(); temperamentCatBreeds.Add(catBreed); } return(temperamentCatBreeds); }
public async Task <ActionResult <CatBreed> > PostCatBreed(CatBreed catBreed) { _context.CatBreeds.Add(catBreed); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCatBreed", new { id = catBreed.Id }, catBreed)); }
public Cat(string name, int age, CatBreed breed) { Name = name; PetType = PetType.Cat; Age = age; Breed = breed; }
public static Cat AddCat(dynamic dynamicCatInstance) { string catName = dynamicCatInstance.name; int catAge = dynamicCatInstance.age; float catHappiness = (float)dynamicCatInstance.happiness; CatBreed catBreed = (CatBreed)Enum.Parse(typeof(CatBreed), dynamicCatInstance.breed); Cat cat = new Cat(catName, catAge, catHappiness, catBreed); return(cat); }
public void WhenIBuyACatWithAnAgeOfAndHappiness(string name, string breed, int age, float happiness) { try { CatBreed catBreed = (CatBreed)Enum.Parse(typeof(CatBreed), breed); var cat = new Cat(name, age, happiness, catBreed); } catch (Exception) { throw new Exception("Catbreed not found. Catbreeds can be: " + EnumUtil.GetAllValuesAsString <CatBreed>()); } }
public Cat(byte age, string name, Gender catGender, CatBreed breed, List <CatFurColor> furColors, bool isCatCaptured) : base(age, name, catGender) { Breed = breed; _isCatCaptured = isCatCaptured; if (furColors == null || furColors.Count < 1) { throw new Exception("Wrong Fur Colors"); } else { _furColors = new List <CatFurColor>(furColors); } }
/// <summary> /// Parameterized Constructor /// </summary> public Cat(string name, CatBreed breed, GenderType gender, int age) { Name = name; Breed = breed; Gender = gender; Age = age; // Photo Assembly asm = Assembly.GetExecutingAssembly(); string path1 = "MakeACatWCFServiceApplication.App_Data.photos."; string path2 = Breed.ToString(); string filepath = path1 + path2 + ".jpg"; Photo = new Bitmap(asm.GetManifestResourceStream(filepath)); } // end of constructor
public void SpawnCatsRandom(int howManyCats) { Bounds bounds = spawnArea.bounds; Vector2 center = bounds.center; for (int i = 0; i < howManyCats; i++) { float x = 0; float y = 0; do { x = Random.Range(center.x - bounds.extents.x, center.x + bounds.extents.x); y = Random.Range(center.y - bounds.extents.y, center.x + bounds.extents.y); } while (!spawnArea.OverlapPoint(new Vector2 { x = x, y = y })); GameObject cat = Instantiate(catPrefab, new Vector3 { x = 0f, y = 0f, z = 0f }, Quaternion.identity); cat.transform.SetParent(catWrapper.transform, false); //place cat at random point cat.transform.localPosition = new Vector3 { x = x, y = y, z = 0f }; // Set the breed of the cat to a random breed from the breed dictionary CatStyle catStyle = catPrefab.GetComponent <CatStyle>(); // TEMPORARY CODE TO LIMIT BREEDS TO BELLYCAT CatBreed breedInfo = breedArray[(int)Random.Range(0f, breedArray.Length - 1)]; while (breedInfo.variantSprite != bellyCat) { breedInfo = breedArray[(int)Random.Range(0f, breedArray.Length - 1)]; } catStyle.breedData = breedInfo; cat.GetComponent <CatBehavior>().fondness = breedInfo.breedFondnessMult; } }
public Tomcat(string name, int age, CatBreed breed) : base(name, age, Gender.Male, breed) { }
public Cat(string name, int age, Gender sex, CatBreed breed) : base(name, age, sex) { Breed = breed; }
public Kitten(string name, int age, CatBreed breed) : base(name, age, Gender.Female, breed) { }
public Cat(CatBreed breed, string name, int age) { Breed = breed.ToString(); Name = name; Age = age; }
public Cat(string name, int age, CatBreed breed) { Name = name; Age = age; _Breed = breed; }
} // end of load names /// <summary> /// Makes a Cat /// </summary> /// <param name="name">Name (string) of the cat</param> /// <param name="breed">Breed (CatBreed) of the cat</param> /// <param name="gender">Gender (GenderType) of the cat</param> /// <param name="age">Age (int) of the cat</param> /// <returns></returns> public Cat MakeACat(string name, CatBreed breed, GenderType gender, int age) { Cat cat = new Cat(name, breed, gender, age); return(cat); }
public static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Information) .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); var host = new HostBuilder() .UseConsoleLifetime() .UseSerilog() .ConfigureServices(services => { services .AddDbContext <MyAppContext>(options => { // options.UseLoggerFactory(MyLoggerFactory); options.UseSqlite(Constants.ConnectionString, sqliteOptions => { sqliteOptions.MigrationsAssembly(typeof(MyAppContext).GetTypeInfo().Assembly.GetName().Name); }); }); AutoMapper.Mapper.Reset(); AutoMapper.Mapper.Initialize(cfg => { cfg.ForAllMaps((typeMap, expression) => { // We should never allow saving an IAuditable thing to an IEntity. This may lead to properties like `UpdatedOn` being edited! // IEntity's that are also IAuditable will have their auditable properties saved by overrides on the DbContext. // Additional Note: Line items are not IEntity. But in general, they are navigation properties and not directly mapped, usually they get mapped by Id and new instances are created. if (typeMap.SourceType.GetInterfaces().Contains(typeof(IAuditable)) && typeMap.DestinationType.GetInterfaces().Contains(typeof(IEntity))) { throw new AutoMapperMappingException($"Source type {typeMap.SourceType.Name} and dest type {typeMap.DestinationType.Name} implements {nameof(IAuditable)}. " + $"Ensure you are not trying to map an auditable VM to an IEntity"); } // Ignore any IAuditable properties from being mapped to an IEntity 9ef entity). // In the tests when we call AssertConfigurationIsValid against the profiles, AutoMapper will complain because the EF entity (which is not always an IEntity) has auditable properties (like UpdatedOn) // This is expected. Because we do not want to be mapping ANYTHING to those audit properties if (typeMap.DestinationType.GetInterfaces().Contains(typeof(IEntity))) { expression .ForMember(nameof(IAuditable.CreatedByDisplayName), opts => opts.Ignore()) .ForMember(nameof(IAuditable.CreatedByWUPeopleId), opts => opts.Ignore()) .ForMember(nameof(IAuditable.UpdatedByDisplayName), opts => opts.Ignore()) .ForMember(nameof(IAuditable.UpdatedByWUPeopleId), opts => opts.Ignore()) .ForMember(nameof(IAuditable.CreatedOnUtc), opts => opts.Ignore()) .ForMember(nameof(IAuditable.UpdatedOnUtc), opts => opts.Ignore()); } }); cfg.CreateMap <CatUpdateViewModel, Cat>() .ForMember(dest => dest.CatBreedLine, opts => opts.MapFrom(src => src.CatBreedIds.Select(id => new CatBreedLine() { CatId = src.Id, CatBreedId = id }))); }); // Dont create audit json files by default. Audit.Core.Configuration.DataProvider = new NullDataProvider(); Audit.EntityFramework.Configuration.Setup() .ForContext <MyAppContext>(config => { config .AuditEventType("{context}:{database}") .IncludeEntityObjects(); }); Audit.Core.Configuration.AddCustomAction(ActionType.OnScopeCreated, scope => { scope.SetCustomField("IdentityId", "Anonymous"); scope.SetCustomField("IdentityDisplayName", "Anonymous"); scope.SetCustomField("CorrelationId", Guid.NewGuid().ToString()); }); Audit.Core.Configuration.Setup() .UseEntityFramework(x => x.AuditTypeMapper(t => typeof(GenericAudit)) // auditEvent https://github.com/thepirat000/Audit.NET/blob/master/src/Audit.NET/AuditEvent.cs (IAuditOutput) // Can be casted to a https://github.com/thepirat000/Audit.NET/blob/master/src/Audit.EntityFramework/EntityFrameworkEvent.cs (IAuditOutput) // eventEntry https://github.com/thepirat000/Audit.NET/blob/master/src/Audit.EntityFramework/EventEntry.cs (IAuditOutput) // This is our entity // auditEntity is the actual IAudit entity .AuditEntityAction <IGenericAudit>((auditEvent, eventEntry, auditEntity) => { var entityFrameworkEvent = auditEvent.GetEntityFrameworkEvent(); var auditableEventEntry = (IAuditable)eventEntry.Entity; auditEntity.Action = eventEntry.Action; Console.WriteLine(eventEntry.ToJson()); auditEntity.AuditData = eventEntry.ToJson(); auditEntity.PrimaryKey = string.Join(',', eventEntry.PrimaryKey.Select(k => k.Value.ToString())); auditEntity.AuditDateUtc = auditableEventEntry.UpdatedOnUtc; // Preserve the updated on datetime auditEntity.EntityType = eventEntry.EntityType.Name; auditEntity.AuditIdentity = auditEvent.CustomFields["IdentityId"].ToString(); auditEntity.AuditIdentityDisplayName = auditEvent.CustomFields["IdentityDisplayName"].ToString(); auditEntity.CorrelationId = auditEvent.CustomFields["CorrelationId"].ToString(); auditEntity.MSDuration = auditEvent.Duration; auditEntity.NumObjectsEffected = entityFrameworkEvent.Result; auditEntity.Success = entityFrameworkEvent.Success; auditEntity.ErrorMessage = entityFrameworkEvent.ErrorMessage; })); }) .Build(); using (host) { await host.StartAsync(); var _logger = host.Services.GetService <ILogger <Program> >(); using (var context = host.Services.GetService <MyAppContext>()) { // Delete the SQLite database context.Database.EnsureDeleted(); // Create, migrate and seed the SQLite database context.Database.Migrate(); var newCat = new Cat() { MeowLoudness = 42 }; var newBreed = new CatBreed() { BreedName = "SuperCat" }; context.Cat.Add(newCat); context.CatBreed.Add(newBreed); // Sets the Ids on the above tracked entities. await context.SaveChangesAsync(); // Save the line item creating the many-to-many relationship context.CatBreedLine.Add(new CatBreedLine() { CatId = newCat.Id, CatBreedId = newBreed.Id }); await context.SaveChangesAsync(); // The update! Bug: This bumps the createdon and updated dates even though this never changed!!!! // Create a new VM of an existing cat to save var catToSave = new CatUpdateViewModel() { Id = newCat.Id, MeowLoudness = 100, CatBreedIds = new List <int> { newBreed.Id } }; var existingCatEntity = await context.Cat .SingleOrDefaultAsync(x => x.Id == newCat.Id); // Mutate existingCatEntity AutoMapper.Mapper.Map(catToSave, existingCatEntity); await context.SaveChangesAsync(); } Console.ReadKey(); await host.StopAsync(TimeSpan.FromSeconds(5)); } }
public Cat(string Name, int Age, CatBreed catBreed) : base(Name, Age) { name = Name; age = Age; CatBreed = catBreed; }