public Owner CreateOwner(Owner createOwner) { if (string.IsNullOrEmpty(createOwner.FirstName)) { throw new InvalidDataException("Insert first name!"); } if (string.IsNullOrEmpty(createOwner.LastName)) { throw new InvalidDataException("Insert last name!"); } if (string.IsNullOrEmpty(createOwner.Address)) { throw new InvalidDataException("Insert a valid address!"); } if (createOwner.PhoneNumber.Length < 8) { throw new InvalidDataException("Must have 8 digits. Ex: 12345678"); } if (string.IsNullOrEmpty(createOwner.Username)) { throw new InvalidDataException("Write a damn username for login"); } if (string.IsNullOrEmpty(createOwner.PassW) && createOwner.PassW.Length <= 10) { throw new InvalidDataException("Must have 10 or more elements"); } return(_ownerRepository.CreateOwner(createOwner)); }
public AppMutation(IOwnerRepository repository) { Field <OwnerType>( "createOwner", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <OwnerInputType> > { Name = "owner" }), resolve: context => { var owner = context.GetArgument <Owner>("owner"); return(repository.CreateOwner(owner)); } ); Field <OwnerType>( "updateOwner", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <OwnerInputType> > { Name = "owner" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "ownerId" }), resolve: context => { var owner = context.GetArgument <Owner>("owner"); var ownerId = context.GetArgument <Guid>("ownerId"); var dbOwner = repository.GetById(ownerId); if (dbOwner == null) { context.Errors.Add(new ExecutionError("Couldn't find owner in db.")); return(null); } return(repository.UpdateOwner(dbOwner, owner)); } ); Field <StringGraphType>( "deleteOwner", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "ownerId" }), resolve: context => { var ownerId = context.GetArgument <Guid>("ownerId"); var owner = repository.GetById(ownerId); if (owner == null) { context.Errors.Add(new ExecutionError("Couldn't find owner in db.")); return(null); } repository.DeleteOwner(owner); return($"The owner with the id: {ownerId} has been successfully deleted from db."); } ); }
public Owner AddOwner(Owner owner) { Owner theOwner = _ownerRepository.CreateOwner(owner); _ownerRepository.GetAllOwners().Add(theOwner); return(theOwner); }
//new method for restApi public Owner CreateOwner(Owner owner) { if (owner == null) { throw new InvalidDataException("The owner object is null and therefor invalid"); } return(_ownerRepo.CreateOwner(owner)); }
public Owner CreateOwner(Owner newOwner) { if (newOwner.Name.Equals(null) || newOwner.Age < 0) { throw new Exception("Missing or wrong Owner information"); } return(_ownerRepo.CreateOwner(newOwner)); }
public Owner CreateOwner(Owner owner) { if (owner.FirstName.Length < 1 || owner.LastName.Length < 1) { throw new System.IO.InvalidDataException("You need to put in atleast 1 letter!"); } return(_ownerRepository.CreateOwner(owner)); }
public AppMutation(IOwnerRepository repository) { Field <OwnerType>( "createOwner", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <OwnerInputType> > { Name = "owner" }), resolve: context => { var owner = context.GetArgument <Owner>("owner"); return(repository.CreateOwner(owner)); }); Field <OwnerType>( "updateOwner", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <OwnerInputType> > { Name = "owner" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "ownerId" }), resolve: context => { var ownerId = context.GetArgument <Guid>("ownerId"); var owner = context.GetArgument <Owner>("owner"); var ownerDb = repository.GetById(ownerId); if (ownerDb == null) { context.Errors.Add(new ExecutionError("Couldn't find owner in db.")); return(null); } return(repository.UpdateOwner(ownerDb, owner)); } ); Field <StringGraphType>( "deleteOwner", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "ownerId" }), resolve: context => { Guid id; if (!Guid.TryParse(context.GetArgument <string>("ownerId"), out id)) { context.Errors.Add(new ExecutionError("Id Invalid")); return(null); } var owner = repository.GetById(id); return(repository.DeleteOwner(owner)); } ); }
public Owner CreateOwner(Owner owner) { //if (!owner.Email.Contains("@")) //{ // throw new Exception("Not a valid email."); //} //else { return(_ownerRepository.CreateOwner(owner)); } }
public Owner AddOwner(Owner owner) { if (owner.FirstName == null || owner.LastName == null) { throw new NullReferenceException("You can't create an owner without a full name!"); } else if (owner.ID == 0 || _ownRepo.ReadOwnerById(owner.ID) == null) { throw new NullReferenceException("There's no such owner in the database!"); } return(_ownRepo.CreateOwner(owner)); }
public Owner AddOwner(string firstName, string lastName, string address, string phoneNr, string email) { Owner newOwner = new Owner { FirstName = firstName, LastName = lastName, Address = address, PhoneNumber = phoneNr, Email = email }; return(_ownerRepository.CreateOwner(newOwner)); }
public Owner CreateOwner(Owner owner) { owner.Validate(); var existingCustomer = _owner.GetOwnerByEmail(owner.Email); if (existingCustomer == null) { var newOwner = _owner.CreateOwner(owner); return(newOwner); } else { throw new Exception("Owner already exists"); } }
public Owner CreateOwner(Owner owner) { if (owner.FirstName == null || owner.FirstName.Any(char.IsDigit) || owner.LastName == null || owner.LastName.Any(char.IsDigit)) { throw new InvalidDataException( "Owner must have a first and last name and they can not contain numbers."); } if (owner.Email == null || owner.PhoneNumber == null) { throw new InvalidDataException("Owner must have an email and phone number."); } if (owner.FirstName.Length < 2) { throw new InvalidDataException("First name must be at least 2 characters."); } if (owner.LastName.Length < 2) { throw new InvalidDataException("Last name must be at least 2 characters."); } if (!owner.Email.Contains("@") || !owner.Email.Contains(".")) { throw new InvalidDataException("Not a valid email."); } if (owner.PhoneNumber.Length < 8) { throw new InvalidDataException("Phone number must be at least 8 numbers."); } if (!(owner.Address.Any(char.IsDigit) && owner.Address.Any(char.IsLetter))) { throw new InvalidDataException("Address must contain both letters and numbers."); } if (owner.Email.Length < 7) { throw new InvalidDataException("Email must be at least 7 characters."); } return(_ownerRepository.CreateOwner(owner)); }
public Owner AddOwner(Owner owner) { if (owner.FirstName.Length == null || owner.LastName.Length == null) { throw new Exception("Both firstname and lastname must be entered"); } if (owner.Address == null) { throw new Exception("The address you have entered is invalid."); } if (owner.PhoneNumber.ToString().Length < 8) { throw new Exception("The phone number must at least contain 8 digits."); } return(_ownerRepository.CreateOwner(owner)); }
public Owner AddOwner(Owner owner) { //Check phone number validity if (!Regex.Match(owner.PhoneNumber, @"^(\+[0-9]{8})$").Success) { return(null); } //Verify email address //https://docs.microsoft.com/en-us/dotnet/standard/base-types/how-to-verify-that-strings-are-in-valid-email-format if (!Regex.Match(owner.Email, @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" + @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-0-9a-z]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$", RegexOptions.IgnoreCase).Success) { return(null); } return(_ownerRepository.CreateOwner(owner)); }
public Owner CreateOwner(string firstName, string lastName, int phoneNumber) { if (string.IsNullOrEmpty(firstName)) { throw new InvalidDataException("An owner must have a first name"); } if (string.IsNullOrEmpty(lastName)) { throw new InvalidDataException("An owner must have a last name"); } if (phoneNumber.ToString().Length != 8) { throw new InvalidDataException("The number must have 8 digits"); } Owner toAdd = new Owner(GetNextAvailableOwnerId(), firstName, lastName, phoneNumber); return(_ownerRep.CreateOwner(toAdd)); }
public Owner CreateOwner(Owner owner) { if (string.IsNullOrEmpty(owner.FirstName)) { throw new InvalidDataException("Invalid Data: The owner's First Name can't be empty"); } if (string.IsNullOrEmpty(owner.LastName)) { throw new InvalidDataException("Invalid Data: The owner's Last Name can't be empty"); } if (string.IsNullOrEmpty(owner.Address)) { throw new InvalidDataException("Invalid Data: The owner's Address can't be empty"); } if (string.IsNullOrEmpty(owner.Email)) { throw new InvalidDataException("Invalid Data: The owner's Email can't be empty"); } if (string.IsNullOrEmpty(owner.PhoneNumber)) { throw new InvalidDataException("Invalid Data: The owner's Phone Number can't be empty"); } return(_ownerRepo.CreateOwner(owner)); }
public async Task <Owner> CreateOwner(Owner owner) { if (owner == null) { throw new QueryException( ErrorBuilder.New() .SetMessage("Please provide valid data") .SetCode("OWNER_NULL") .Build()); } var result = await _repository.CreateOwner(owner); if (!string.IsNullOrEmpty(result.ErrorMessage)) { throw new QueryException( ErrorBuilder.New() .SetMessage(result.ErrorMessage) .SetCode("ERROR") .Build()); } return(result.ModelData); }
public Owner CreateOwner(Owner owner) { Owner ownerAdd; if (owner == null) { throw new InvalidDataException("missing owner to add"); } else if (owner.FirstName.Length < 1) { throw new InvalidDataException("owners first name is to short"); } else if (owner.LastName.Length < 1) { throw new InvalidDataException("owner last name is to short"); } ownerAdd = _ownerRepository.CreateOwner(owner); if (ownerAdd == null) { throw new DataException("could not add owner"); } return(ownerAdd); }
public Owner CreateOwner(Owner createdOwner) { return(_ownerRepo.CreateOwner(createdOwner)); }
public AppMutation(IOwnerRepository repository) { //createOwner glecek ve argümanu owner olacak bu owner ownerInputType tipinde olacak Field <OwnerType>( "createOwner", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <OwnerInputType> > { Name = "owner" }), resolve: context => { //contextin içindeki owner nesnesi Owner tipine dönüştürülecek ve entity tipinde return edilecek var owner = context.GetArgument <Owner>("owner"); return(repository.CreateOwner(owner)); }); //update owner mutation gelecek 2 tane argümanı olacak biri owner diğeri ownerId //bunlar Owner tipine ve Guid tipine resolve edilecek //eğere db de böyle bir kullanıcı varsa update eder //yoksa hata dönecek Field <OwnerType>( "updateOwner", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <OwnerInputType> > { Name = "owner" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "ownerId" }), resolve: context => { var owner = context.GetArgument <Owner>("owner"); var ownerId = context.GetArgument <Guid>("ownerId"); var dbOwner = repository.GetById(ownerId); if (dbOwner != null) { return(repository.UpdateOwner(dbOwner, owner)); } context.Errors.Add(new ExecutionError("Couldnt find the owner")); return(null); }); Field <StringGraphType>( "deleteOwner", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "ownerId" }), resolve: context => { var ownerId = context.GetArgument <Guid>("ownerId"); var owner = repository.GetById(ownerId); if (owner != null) { repository.DeleteOwner(owner); return($"Owner with {ownerId} id deleted"); } context.Errors.Add(new ExecutionError("Couldnt find the user")); return(null); }); }
public void InitData() { Owner owner1 = _ownerRepository.CreateOwner(new Owner() { FirstName = "John", LastName = "Johnson", Address = "Mock Street 1", PhoneNumber = "000000000", Email = "*****@*****.**" }); Owner owner2 = _ownerRepository.CreateOwner(new Owner() { FirstName = "Jack", LastName = "Jackson", Address = "Mock Street 2", PhoneNumber = "000000000", Email = "*****@*****.**" }); Owner owner3 = _ownerRepository.CreateOwner(new Owner() { FirstName = "Uncle", LastName = "Bob", Address = "Mock Street 3", PhoneNumber = "000000000", Email = "*****@*****.**" }); Owner owner4 = _ownerRepository.CreateOwner(new Owner() { FirstName = "Martin", LastName = "Fowler", Address = "Mock Street 4", PhoneNumber = "000000000", Email = "*****@*****.**" }); Owner owner5 = _ownerRepository.CreateOwner(new Owner() { FirstName = "Kent", LastName = "Beck", Address = "Mock Street 5", PhoneNumber = "000000000", Email = "*****@*****.**" }); Owner owner6 = _ownerRepository.CreateOwner(new Owner() { FirstName = "Charles", LastName = "Darwin", Address = "Mock Street 6", PhoneNumber = "000000000", Email = "*****@*****.**" }); _petRepository.CreatePet(new Pet() { Name = "Snoopy", Type = PetType.Dog, BirthDate = DateTime.Parse("01-01-2020"), SoldDate = DateTime.Parse("01-06-2020"), Color = "White", PreviousOwner = owner1, Price = 2500 }); _petRepository.CreatePet(new Pet() { Name = "Garfield", Type = PetType.Cat, BirthDate = DateTime.Parse("01-12-2019"), SoldDate = DateTime.Parse("01-05-2020"), Color = "Orange", PreviousOwner = owner2, Price = 2000 }); _petRepository.CreatePet(new Pet() { Name = "Clean Cat", Type = PetType.Cat, BirthDate = DateTime.Parse("01-12-2010"), SoldDate = DateTime.Parse("01-05-2012"), Color = "White/red", PreviousOwner = owner3, Price = 3000 }); _petRepository.CreatePet(new Pet() { Name = "Fowl", Type = PetType.Parrot, BirthDate = DateTime.Parse("01-12-2016"), SoldDate = DateTime.Parse("01-05-2017"), Color = "White", PreviousOwner = owner4, Price = 5000 }); _petRepository.CreatePet(new Pet() { Name = "Bugs Bunny", Type = PetType.Rabbit, BirthDate = DateTime.Parse("01-12-2018"), SoldDate = DateTime.Parse("01-05-2019"), Color = "White/grey", PreviousOwner = owner5, Price = 1500 }); _petRepository.CreatePet(new Pet() { Name = "Aesop", Type = PetType.Turtle, BirthDate = DateTime.Parse("15-09-1830"), SoldDate = DateTime.Parse("15-09-1835"), Color = "Green", PreviousOwner = owner6, Price = 3500 }); }
public void CreateOwner(Owner owner) { ownerRepository.CreateOwner(owner); }
public Owner CreateOwner(Owner ownerToCreate) { var validatedOwner = ValidateOwner(ownerToCreate, false); return(_ownerRepository.CreateOwner(validatedOwner)); }
public void InitData() { var pet1 = new Pet() { Name = "Billy", Type = new PetType() { Id = 1 }, BirthDate = DateTime.Now.AddYears(-2), Color = "White", PreviousOwner = "Joe", Price = 500, SoldDate = DateTime.Now.AddYears(-2), Owner = new Owner() { Id = 1 } }; _petRepo.CreatePet(pet1); var pet2 = new Pet() { Name = "Bob", Type = new PetType() { Id = 2 }, BirthDate = DateTime.Now.AddYears(-3), Color = "Black", PreviousOwner = "Michael", Price = 100, SoldDate = DateTime.Now.AddYears(-1), Owner = new Owner() { Id = 2 } }; _petRepo.CreatePet(pet2); var pet3 = new Pet() { Name = "Joe", Type = new PetType() { Id = 3 }, BirthDate = DateTime.Now.AddYears(-10), Color = "Orange", PreviousOwner = "Tommy", Price = 1500, SoldDate = DateTime.Now.AddYears(-2), Owner = new Owner() { Id = 2 } }; _petRepo.CreatePet(pet3); var pet4 = new Pet() { Name = "Timmy", Type = new PetType() { Id = 1 }, BirthDate = DateTime.Now.AddYears(-2), Color = "Brown", PreviousOwner = "Dimitri", Price = 1250, SoldDate = DateTime.Now.AddYears(-1), Owner = new Owner() { Id = 2 } }; _petRepo.CreatePet(pet4); var pet5 = new Pet() { Name = "Splinter", Type = new PetType() { Id = 2 }, BirthDate = DateTime.Now.AddYears(-3), Color = "Grey", PreviousOwner = "Michael", Price = 50, SoldDate = DateTime.Now.AddYears(-1), Owner = new Owner() { Id = 1 } }; _petRepo.CreatePet(pet5); var pet6 = new Pet() { Name = "Mujo", Type = new PetType() { Id = 3 }, BirthDate = DateTime.Now.AddYears(-2), Color = "Yellow", PreviousOwner = "Betty", Price = 145, SoldDate = DateTime.Now.AddYears(-1), Owner = new Owner() { Id = 2 } }; _petRepo.CreatePet(pet6); var owner1 = new Owner() { FirstName = "Bob", LastName = "Bobsen", Address = "Storegade 1", PhoneNumber = 12345678, }; _ownerRepo.CreateOwner(owner1); var owner2 = new Owner() { FirstName = "Joe", LastName = "Cool", Address = "Langevej 1", PhoneNumber = 22345678 }; _ownerRepo.CreateOwner(owner2); var type1 = new PetType() { Type = "Dog" }; _typeRepo.CreatePetType(type1); var type2 = new PetType() { Type = "Cat" }; _typeRepo.CreatePetType(type2); var type3 = new PetType() { Type = "Bird" }; _typeRepo.CreatePetType(type3); }
public Owner AddNewOwner(Owner newOwner) { return(ownerrepo.CreateOwner(newOwner)); }
public Owner AddOwner(Owner owner) { return(_ownerRepository.CreateOwner(owner)); }
public void InitData() { // OWNERS Owner owner1 = new Owner() { Name = "Cobber McCorker", Address = "30 Happy Pet Lane", PetsOwned = null // new Pet() {PetId = 11}) }; _ownerRepo.CreateOwner(owner1); Owner owner2 = new Owner() { Name = "Daevid Allen", Address = "Planet Gong", PetsOwned = null }; _ownerRepo.CreateOwner(owner2); Owner owner3 = new Owner() { Name = "Jake Roberts", Address = "12 Reptile Rd", PetsOwned = null }; _ownerRepo.CreateOwner(owner3); Owner owner4 = new Owner() { Name = "Ginger Buns", Address = "43 Muffin Grove", PetsOwned = null }; _ownerRepo.CreateOwner(owner4); Owner owner5 = new Owner() { Name = "Marty MyFries", Address = "1955 Future Path", PetsOwned = null }; _ownerRepo.CreateOwner(owner5); Owner owner6 = new Owner() { Name = "Henry Hippo", Address = "90 Zoo Gardens", PetsOwned = null }; _ownerRepo.CreateOwner(owner6); // PET TYPES PetType petType1 = new PetType() { Name = "Snake" }; _petTypeRepo.CreatePetType(petType1); PetType petType2 = new PetType() { Name = "Cat" }; _petTypeRepo.CreatePetType(petType2); PetType petType3 = new PetType() { Name = "Dog" }; _petTypeRepo.CreatePetType(petType3); PetType petType4 = new PetType() { Name = "Wombat" }; _petTypeRepo.CreatePetType(petType4); PetType petType5 = new PetType() { Name = "Fish" }; _petTypeRepo.CreatePetType(petType5); PetType petType6 = new PetType() { Name = "Iguana" }; _petTypeRepo.CreatePetType(petType6); PetType petType7 = new PetType() { Name = "Frog" }; _petTypeRepo.CreatePetType(petType7); PetType petType8 = new PetType() { Name = "Rabbit" }; _petTypeRepo.CreatePetType(petType8); PetType petType9 = new PetType() { Name = "Giraffe" }; _petTypeRepo.CreatePetType(petType9); PetType petType10 = new PetType() { Name = "Spider" //SubType = "Black Widow" }; _petTypeRepo.CreatePetType(petType10); // PETS Pet pet1 = new Pet() { Name = "Geoff", Type = petType1, // Gender = Convert.ToChar("F"), BirthDate = Convert.ToDateTime("1992-12-15"), SoldDate = Convert.ToDateTime("2019-11-15"), Colour = "Red", PreviousOwner = owner3, Price = 330 }; _petRepo.CreatePet(pet1); Pet pet2 = new Pet() { Name = "Leo Long", Type = petType6, // Gender = Convert.ToChar("M"), BirthDate = Convert.ToDateTime("1920-12-14"), SoldDate = Convert.ToDateTime("2012-11-15"), Colour = "Blue", PreviousOwner = owner1, Price = 1250 }; _petRepo.CreatePet(pet2); Pet pet3 = new Pet() { Name = "Freddy", Type = petType7, // Gender = Convert.ToChar("M"), BirthDate = Convert.ToDateTime("1930-12-14"), SoldDate = Convert.ToDateTime("2013-11-15"), Colour = "Orange", PreviousOwner = owner6, Price = 56 }; _petRepo.CreatePet(pet3); Pet pet4 = new Pet() { Name = "Jake", Type = petType1, // Gender = Convert.ToChar("M"), BirthDate = Convert.ToDateTime("1940-12-14"), SoldDate = Convert.ToDateTime("2014-11-15"), Colour = "White", PreviousOwner = owner3, Price = 343 }; _petRepo.CreatePet(pet4); Pet pet5 = new Pet() { Name = "Jeremy", Type = petType2, // Gender = Convert.ToChar("M"), BirthDate = Convert.ToDateTime("2010-12-14"), SoldDate = Convert.ToDateTime("2017-11-15"), Colour = "Blue", PreviousOwner = owner5, Price = 238 }; _petRepo.CreatePet(pet5); Pet pet6 = new Pet() { Name = "Albert", Type = petType3, // Gender = Convert.ToChar("F"), BirthDate = Convert.ToDateTime("1992-12-15"), SoldDate = Convert.ToDateTime("2019-11-15"), Colour = "Black", PreviousOwner = owner2, Price = 330 }; _petRepo.CreatePet(pet6); Pet pet7 = new Pet() { Name = " Richard", Type = petType1, // Gender = Convert.ToChar("M"), BirthDate = Convert.ToDateTime("2018-01-14"), SoldDate = Convert.ToDateTime("2019-11-15"), Colour = "Tan", PreviousOwner = owner5, Price = 165 }; _petRepo.CreatePet(pet7); Pet pet8 = new Pet() { Name = "Zues", Type = petType9, // Gender = Convert.ToChar("M"), BirthDate = Convert.ToDateTime("2020-08-14"), SoldDate = Convert.ToDateTime("2020-08-15"), Colour = "Blue", PreviousOwner = owner2, Price = 50 }; _petRepo.CreatePet(pet8); Pet pet9 = new Pet() { Name = "Stan", Type = petType9, // Gender = Convert.ToChar("M"), BirthDate = Convert.ToDateTime("2019-10-14"), SoldDate = Convert.ToDateTime("2019-11-15"), Colour = "White", PreviousOwner = owner5, Price = 150 }; _petRepo.CreatePet(pet9); Pet pet10 = new Pet() { Name = "Selene", Type = petType5, // Gender = Convert.ToChar("M"), BirthDate = Convert.ToDateTime("2017-12-14"), SoldDate = Convert.ToDateTime("2018-11-15"), Colour = "Blue and Yellow", PreviousOwner = owner1, Price = 970 }; _petRepo.CreatePet(pet10); Pet pet11 = new Pet() { Name = "Wally", Type = petType4, // Gender = Convert.ToChar("M"), BirthDate = Convert.ToDateTime("2016-06-04"), SoldDate = Convert.ToDateTime("2018-01-06"), Colour = "Brown", PreviousOwner = owner1, Price = 450 }; _petRepo.CreatePet(pet11); }
public Owner CreateOwner(Owner ownerToCreate) { return(_ownerRepository.CreateOwner(ownerToCreate)); }
public AppMutation(IOwnerRepository ownerRepository, IAccountRepository accountRepository) { #region Owner Mutation Field <OwnerType>( "createOwner", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <OwnerInputType> > { Name = "owner" }), resolve: context => { var owner = context.GetArgument <Owner>("owner"); return(ownerRepository.CreateOwner(owner).Result); } ); Field <OwnerType>( "updateOwner", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "ownerId" }, new QueryArgument <NonNullGraphType <OwnerInputType> > { Name = "owner" }), resolve: context => { var ownerId = context.GetArgument <int>("ownerId"); var owner = context.GetArgument <Owner>("owner"); var updatedOwner = ownerRepository.UpdateOwner(ownerId, owner).Result; if (updatedOwner == null) { context.Errors.Add(new ExecutionError($"Cannot find owner with ID { ownerId }")); return(null); } return(updatedOwner); } ); Field <StringGraphType>( "deleteOwner", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "ownerId" } ), resolve: context => { var ownerId = context.GetArgument <int>("ownerId"); if (ownerRepository.DeleteOwner(ownerId).Result) { return($"The owner with Id { ownerId } deleted successfully"); } context.Errors.Add(new ExecutionError($"Cannot find owner with ID { ownerId }")); return(null); } ); #endregion #region Account Mutation Field <AccountType>( "createAccount", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <AccountInputType> > { Name = "account" } ), resolve: context => { var account = context.GetArgument <Account>("account"); if (account.OwnerId == 0) { context.Errors.Add(new ExecutionError($"Please provide ownerId")); return(null); } return(accountRepository.CreateAccount(account)); } ); Field <AccountType>( "updateAccount", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "accountId" }, new QueryArgument <NonNullGraphType <AccountInputType> > { Name = "account" } ), resolve: context => { var accountId = context.GetArgument <int>("accountId"); var account = context.GetArgument <Account>("account"); var updatedAccount = accountRepository.UpdateAccount(accountId, account).Result; if (updatedAccount == null) { context.Errors.Add(new ExecutionError($"Cannot find owner with ID { accountId }")); return(null); } return(updatedAccount); } ); Field <StringGraphType>( "deleteAccount", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "accountId" } ), resolve: context => { var accountId = context.GetArgument <int>("accountId"); if (accountRepository.DeleteAccount(accountId).Result) { return($"Account with id { accountId } deleted successfully"); } context.Errors.Add(new ExecutionError($"Account with id { accountId } not found")); return(null); } ); #endregion }
public Owner CreateOwner(Owner owner) { return(_ownerRepo.CreateOwner(owner)); }