private void UpdateEntity(IHandlerEntryEntity entity) { using (var ctx = new HappyDogShowContext()) { HandlerEntry foundEntity = ctx.HandlerEntries.Where(d => d.ID == entity.Id).First(); if (foundEntity != null) { if (entity.Dog != null) { DogRegistration selectedDog = ctx.DogRegistrations.Where(i => i.ID == entity.Dog.Id).First(); foundEntity.Dog = selectedDog; } if (entity.DogShow != null) { DogShow selectedShow = ctx.DogShows.Where(i => i.ID == entity.DogShow.Id).First(); foundEntity.Show = selectedShow; } if (entity.Class != null) { HandlerClass selectedClass = ctx.HandlerClasses.Where(i => i.ID == entity.Class.Id).First(); foundEntity.EnteredClass = selectedClass; } foundEntity.Number = entity.Number; ctx.SaveChanges(); } } }
private int CreateEntity(IHandlerEntryEntity entity) { int newid = -1; using (var ctx = new HappyDogShowContext()) { DogRegistration selectedDog = ctx.DogRegistrations.Where(i => i.ID == entity.Dog.Id).First(); DogShow selectedShow = ctx.DogShows.Where(i => i.ID == entity.DogShow.Id).First(); HandlerClass selectedClass = ctx.HandlerClasses.Where(i => i.ID == entity.Class.Id).First(); HandlerRegistration selectedHander = ctx.HandlerRegistrations.Where(i => i.ID == entity.Handler.Id).First(); HandlerEntry newEntity = new HandlerEntry() { Dog = selectedDog, Show = selectedShow, EnteredClass = selectedClass, Handler = selectedHander }; ctx.HandlerEntries.Add(newEntity); ctx.SaveChanges(); newid = newEntity.ID; } return(newid); }
private int CreateEntity(IBreedEntryEntity entity) { int newid = -1; using (var ctx = new HappyDogShowContext()) { DogRegistration selectedDog = ctx.DogRegistrations.Where(i => i.ID == entity.Dog.Id).First(); DogShow selectedShow = ctx.DogShows.Where(i => i.ID == entity.ShowId).First(); List <BreedClassEntry> enteredClasses = new List <BreedClassEntry>(); foreach (var i in entity.Classes.Where(j => j.IsSelected)) { BreedClass breedClass = ctx.BreedClasses.Where(k => k.ID == i.BreedClassID).First(); enteredClasses.Add(new BreedClassEntry() { Class = breedClass });; } if (string.IsNullOrEmpty(entity.Number)) { var usednumbers = ctx.BreedEntries.Where(be => be.Show.ID == entity.ShowId).Select(be => be.Number).ToList().Distinct().ToList(); if (usednumbers.Count > 0) { int temp; int max = usednumbers.Select(n => int.TryParse(n, out temp) ? temp : 0).Max(); if (max > 0) { entity.Number = (max + 1).ToString(); } } else { entity.Number = ""; } } BreedEntry newEntity = new BreedEntry() { Dog = selectedDog, EnteredClasses = enteredClasses, Show = selectedShow, Number = entity.Number }; ctx.BreedEntries.Add(newEntity); ctx.SaveChanges(); newid = newEntity.ID; } return(newid); }
private int CreateEntity(IDogRegistration entity) { int newid = -1; using (var ctx = new HappyDogShowContext()) { Gender entityGender = ctx.Genders.Where(g => g.ID == entity.GenderId).First(); Breed entityBreed = ctx.Breeds.Where(g => g.ID == entity.BreedId).First(); DogRegistration newEntity = new DogRegistration() { RegisrationNumber = entity.RegisrationNumber, Gender = entityGender, DateOfBirth = entity.DateOfBirth, Breed = entityBreed, RegisteredName = entity.RegisteredName, Qualifications = entity.Qualifications, ChipOrTattooNumber = entity.ChipOrTattooNumber, Sire = entity.Sire, Dam = entity.Dam, BredBy = entity.BredBy, Colour = entity.Colour, RegisteredOwnerSurname = entity.RegisteredOwnerSurname, RegisteredOwnerTitle = entity.RegisteredOwnerTitle, RegisteredOwnerInitials = entity.RegisteredOwnerInitials, RegisteredOwnerAddress = entity.RegisteredOwnerAddress, RegisteredOwnerPostalCode = entity.RegisteredOwnerPostalCode, RegisteredOwnerKUSANo = entity.RegisteredOwnerKUSANo, RegisteredOwnerTel = entity.RegisteredOwnerTel, RegisteredOwnerCell = entity.RegisteredOwnerCell, RegisteredOwnerFax = entity.RegisteredOwnerFax, RegisteredOwnerEmail = entity.RegisteredOwnerEmail }; ctx.DogRegistrations.Add(newEntity); ctx.SaveChanges(); newid = newEntity.ID; } return(newid); }
private void UpdateEntity(IDogRegistration entity) { using (var ctx = new HappyDogShowContext()) { DogRegistration foundEntity = ctx.DogRegistrations.Where(d => d.ID == entity.Id).First(); if (foundEntity != null) { Gender entityGender = ctx.Genders.Where(g => g.ID == entity.GenderId).First(); Breed entityBreed = ctx.Breeds.Where(g => g.ID == entity.BreedId).First(); foundEntity.RegisrationNumber = entity.RegisrationNumber; foundEntity.Gender = entityGender; foundEntity.DateOfBirth = entity.DateOfBirth; foundEntity.Breed = entityBreed; foundEntity.RegisteredName = entity.RegisteredName; foundEntity.Qualifications = entity.Qualifications; foundEntity.ChipOrTattooNumber = entity.ChipOrTattooNumber; foundEntity.Sire = entity.Sire; foundEntity.Dam = entity.Dam; foundEntity.BredBy = entity.BredBy; foundEntity.Colour = entity.Colour; foundEntity.RegisteredOwnerSurname = entity.RegisteredOwnerSurname; foundEntity.RegisteredOwnerTitle = entity.RegisteredOwnerTitle; foundEntity.RegisteredOwnerInitials = entity.RegisteredOwnerInitials; foundEntity.RegisteredOwnerAddress = entity.RegisteredOwnerAddress; foundEntity.RegisteredOwnerPostalCode = entity.RegisteredOwnerPostalCode; foundEntity.RegisteredOwnerKUSANo = entity.RegisteredOwnerKUSANo; foundEntity.RegisteredOwnerTel = entity.RegisteredOwnerTel; foundEntity.RegisteredOwnerCell = entity.RegisteredOwnerCell; foundEntity.RegisteredOwnerFax = entity.RegisteredOwnerFax; foundEntity.RegisteredOwnerEmail = entity.RegisteredOwnerEmail; ctx.SaveChanges(); } } }