Пример #1
0
        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.");
            }
                );
        }
Пример #2
0
 public Owner DeleteOwner(int id)
 {
     if (!IdVerifier(id))
     {
         throw new InvalidDataException($"The Id you entered does NOT exist");
     }
     return(_ownerRepo.DeleteOwner(id));
 }
Пример #3
0
 public Owner DeleteOwner(int id)
 {
     if (id < 0)
     {
         throw new Exception("Please, enter a valid value for the ID");
     }
     return(_ownerRepo.DeleteOwner(id));
 }
Пример #4
0
 public void DeleteOwner(int id)
 {
     if (id <= 0)
     {
         throw new InvalidDataException("Owner not found");
     }
     _ownerRepository.DeleteOwner(id);
 }
Пример #5
0
 public Owner DeleteOwner(int id)
 {
     if (!_ownerRepository.ReadOwners().Exists(x => x.Id.Equals(id)))
     {
         throw new KeyNotFoundException("owner could not be found");
     }
     return(_ownerRepository.DeleteOwner(id));
 }
Пример #6
0
 public Owner DeleteOwner(int deletedOwnerId)
 {
     if (deletedOwnerId <= 0)
     {
         throw new Exception("Invalid Id");
     }
     return(_ownerRepo.DeleteOwner(deletedOwnerId));
 }
Пример #7
0
 public Owner DeleteOwner(Owner owner)
 {
     if (owner == null)
     {
         throw new InvalidDataException($"Something went wrong and the owner was null");
     }
     return(_ownerRepo.DeleteOwner(owner));
 }
Пример #8
0
 public Owner DeleteOwner(int id)
 {
     if (id < 1)
     {
         throw new System.IO.InvalidDataException("Id must be atleast 1");
     }
     return(_ownerRepository.DeleteOwner(id));
 }
Пример #9
0
 public Owner DeleteOwner(int id)
 {
     if (id < 1)
     {
         throw new InvalidDataException("ID cannot be lower than 1");
     }
     return(_ownerRepository.DeleteOwner(id));
 }
Пример #10
0
 public Owner RemoveOwner(Owner ownerToDelete)
 {
     if (ownerToDelete != null)
     {
         return(_ownerRepository.DeleteOwner(ownerToDelete.Id));
     }
     throw new InvalidDataException($"The owner you are trying to delete does not exist!");
 }
        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));
            }

                );
        }
Пример #12
0
 public Owner DeleteOwner(int id)
 {
     /*
      * if (_ownerRepository.DeleteOwner(id) == null || id < 1)
      * {
      *  throw new Exception($"The Id {id} was not found.");
      * }
      */
     return(_ownerRepository.DeleteOwner(id));
 }
Пример #13
0
 public ActionResult Delete(int id, Owner owner)
 {
     try
     {
         _ownerRepository.DeleteOwner(id);
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         return(View(owner));
     }
 }
Пример #14
0
        public IActionResult DeleteOwner(int ownerId)
        {
            var ownerFromRepo = _ownerRepository.GetOwner(ownerId);

            if (ownerFromRepo == null)
            {
                return(NotFound());
            }

            _ownerRepository.DeleteOwner(ownerFromRepo);
            return(NoContent());
        }
Пример #15
0
 public Owner DeleteOwner(int ID)
 {
     if (ID <= 0)
     {
         throw new ArgumentException("Incorrect ID entered");
     }
     if (GetOwnerByID(ID) == null)
     {
         throw new ArgumentException("No owner with such ID found");
     }
     return(OwnerRepository.DeleteOwner(ID));
 }
Пример #16
0
 private void deleteOwner_Click(object sender, RoutedEventArgs e)
 {
     if (showOwner.SelectedItem is Owner)
     {
         ownerRepository.DeleteOwner((Owner)showOwner.SelectedItem);
         UpdateSelectedOwner();
     }
     else
     {
         MessageBox.Show("Объект не выбран. Выберите объект для внесения изменений.");
     }
 }
Пример #17
0
 public ActionResult Delete(int id, IFormCollection collection)
 {
     try
     {
         _ownerRepo.DeleteOwner(id);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Пример #18
0
 public ActionResult Delete(int id, Owner owner)
 {
     try
     {
         _ownerRepo.DeleteOwner(id);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View(owner));
     }
 }
Пример #19
0
        public Owner DeleteOwnerByID(int theId)
        {
            List <Owner> toBeDeletedOwners = _ownerRepo.FindOwner(theId);

            if (toBeDeletedOwners.Count != 1)
            {
                throw new Exception("Could not find anyone to delete.");
            }
            else
            {
                return(_ownerRepo.DeleteOwner(toBeDeletedOwners[0]));
            }
        }
        public ActionResult <Owner> Delete(int id)
        {
            Owner result = _ownerRepository.DeleteOwner(id);

            if (result != null)
            {
                return(Ok("Owner with ID: " + id + " has been deleted!"));
            }
            else
            {
                return(BadRequest("Something went wrong!"));
            }
        }
Пример #21
0
        public async Task DeleteOwner(int id)
        {
            var log = new Log()
            {
                Name  = "DeleteOwner",
                Time  = DateTime.Now,
                Index = id
            };

            await _collection.InsertOneAsync(log);

            await _repository.DeleteOwner(id);
        }
Пример #22
0
 public ActionResult Delete(int id, Owner owner)
 {
     //if owner is deleted the user will be redirected to the index page
     //otherwise the user will stay on the delete page to fix the error
     try
     {
         _ownerRepo.DeleteOwner(id);
         return(RedirectToAction(nameof(Index)));
     }
     catch (Exception)
     {
         return(View(owner));
     }
 }
Пример #23
0
        public Owner DeleteOwner(int id)
        {
            Owner ownerToDelete;

            if (!_ownerRepository.GetAllOwners().Exists(x => x.ID == id))
            {
                throw new KeyNotFoundException("An owner with this ID does not exist");
            }
            else
            {
                ownerToDelete = _ownerRepository.GetAllOwners().Find(x => x.ID == id);
                return(_ownerRepository.DeleteOwner(ownerToDelete));
            }
        }
Пример #24
0
        public ActionResult Delete(int id, Owner owner)
        {
            try
            {
                _ownerRepo.DeleteOwner(id);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(View(owner));
            }
        }
Пример #25
0
        public Owner DeleteOwner(Owner toDelete)
        {
            // Delete all pets of the owner
            List <Pet> allPets = _petRep.GetAllPets().ToList();

            foreach (var pet in allPets)
            {
                if (pet.CurrentOwner.Id == toDelete.Id)
                {
                    _petRep.DeletePet(pet);
                }
            }
            // Delete the owner
            return(_ownerRep.DeleteOwner(toDelete));
        }
        public Owner DeleteOwner(int id)
        {
            if (id < 0)
            {
                throw new InvalidDataException("ID can't be under zero");
            }
            var OwnerToDelete = ownerrepo.GetOwnerByID(id);

            if (OwnerToDelete == null)
            {
                throw new InvalidDataException("Owner Can't be 'NULL'");
            }
            else
            {
                ownerrepo.DeleteOwner(OwnerToDelete);
                return(OwnerToDelete);
            }
        }
Пример #27
0
 public ActionResult DeleteConfirmed(int id)
 {
     try
     {
         Owner Owner = OwnerRepository.GetOwnerByID(id);
         OwnerRepository.DeleteOwner(id);
         OwnerRepository.Save();
     }
     catch (DataException)
     {
         //Log the error (add a variable name after DataException)
         return(RedirectToAction("Delete",
                                 new System.Web.Routing.RouteValueDictionary {
             { "id", id },
             { "saveChangesError", true }
         }));
     }
     return(RedirectToAction("Index"));
 }
Пример #28
0
        public async Task <IActionResult> DeleteOwner(int id)
        {
            try
            {
                var ownerEntity = await _repository.GetOwner(id);

                if (ownerEntity == null)
                {
                    return(NotFound());
                }

                _repository.DeleteOwner(ownerEntity.Value);
                await _repository.SaveAsync();

                return(NoContent());
            }
            catch (Exception)
            {
                return(StatusCode(500, "Internal server error"));
            }
        }
        public async Task <string> DeleteOwner(int ownerId)
        {
            if (ownerId == 0)
            {
                throw new QueryException(
                          ErrorBuilder.New()
                          .SetMessage($"Please provide owner id")
                          .SetCode("OWNER_ID_NULL")
                          .Build());
            }

            if (await _repository.DeleteOwner(ownerId))
            {
                return($"Owner with id { ownerId } deleted successfully");
            }
            else
            {
                throw new QueryException(
                          ErrorBuilder.New()
                          .SetMessage($"Owner with id { ownerId } not found")
                          .SetCode("OWNER_NOT_FOUND")
                          .Build());
            }
        }
Пример #30
0
 public async Task DeleteAccount(int id)
 {
     await _ownerRepository.DeleteOwner(id);
 }