public ResponseMessage SetClientPets(PetsEntity petsEntity) { ResponseMessage replay = new ResponseMessage(); try { int id = ValidSecurityToken(authHeader); ClientsController controller = new ClientsController(); if (petsEntity.ClientId == id) { controller.SetPetsClient(petsEntity); replay.Success = true; replay.Message = "Pet insert or update successfully"; } else { replay.Success = false; replay.Message = "This Pet is not of this client"; } return(replay); } catch (Exception ex) { replay.Success = false; replay.Message = ex.Message; replay.Exception = ex.Treatment(); return(replay); } }
public VaccinationEntity[] GetPetVaccination(PetsEntity petsEntity) { if (petsEntity == null) { throw new ArgumentNullException("petsEntity", "petsEntity is null"); } if (petsEntity.Id <= 0) { throw new ArgumentNullException("petsEntity.Id", "petsEntity.ID is null"); } return(GetPetVaccination(petsEntity.Id)); }
public HistoricEntity[] GetPetHistoric(PetsEntity petsEntity) { if (petsEntity == null) { throw new ArgumentNullException("petsEntity", "petsEntity is null"); } if (petsEntity.Id <= 0) { throw new ArgumentNullException("petsEntity.Id", "petsEntity.ID is null"); } return(GetPetHistoric(petsEntity.Id)); }
public void DeletePetsClient(PetsEntity petEntity, int?userId = null) { if (petEntity == null) { throw new ArgumentNullException("petEntity", "petEntity is null"); } if (petEntity.Id <= 0) { throw new ArgumentNullException("petEntity.Id", "petEntity.ID is null"); } if (petEntity.ClientId <= 0) { throw new ArgumentNullException("petEntity.ClientId", "ClientID is null"); } using (Petz_dbEntities db = new Petz_dbEntities()) { //update Boolean isPetClient = false; if (petEntity.ClientId > 0) { isPetClient = db.petz_Client_Pet.Count(x => x.pet_id == petEntity.Id && x.client_id == petEntity.ClientId) == 1; } if (isPetClient) { petz_Pets pet = db.petz_Pets.FirstOrDefault(x => x.pet_id == petEntity.Id); if (pet != null) { if (userId != null && userId > 0) { pet.update_user_id = userId.Value; } else { pet.update_client_id = petEntity.ClientId; } pet.date_delete = DateTime.Now; db.SaveChanges(); } } else { throw new ArgumentOutOfRangeException("petEntity.Id", "This Pet is not of this client"); } } }
public ResponseMessage DeleteClientPets(PetsEntity petsEntity) { ResponseMessage replay = new ResponseMessage(); try { int id = ValidSecurityToken(authHeader); ClientsController controller = new ClientsController(); controller.DeletePetsClient(petsEntity, id); replay.Success = true; replay.Message = "Pet delete successfully"; return(replay); } catch (Exception ex) { replay.Success = false; replay.Message = ex.Message; replay.Exception = ex.Treatment(); return(replay); } }
public void SetPetsClient(PetsEntity petEntity, int?userId = null) { if (petEntity == null) { throw new ArgumentNullException("petEntity", "petEntity is null"); } if (petEntity.SubSpecies == null || petEntity.SubSpecies.Id <= 0) { throw new ArgumentNullException("petEntity.SubSpecies", "petEntity.SubSpecies is null"); } if (petEntity.Size == null || petEntity.Size.Id <= 0) { throw new ArgumentNullException("petEntity.Size", "petEntity.Size is null"); } if (petEntity.ClientId <= 0) { throw new ArgumentNullException("petEntity.ClientId", "ClientID is null"); } using (Petz_dbEntities db = new Petz_dbEntities()) { if (petEntity.Id <= 0) { //Novo petz_Pets pet = new petz_Pets(); if (userId != null && userId > 0) { pet.insert_user_id = userId.Value; } else { pet.insert_client_id = petEntity.ClientId; } pet.pet_birthday = petEntity.Birthday; pet.pet_color = petEntity.Color; pet.pet_document = petEntity.Document; pet.pet_name = petEntity.Name; pet.pet_nickname = petEntity.NickName; pet.pet_profile_facebook = petEntity.Facebook; pet.pet_weight = petEntity.Weight; pet.size_id = petEntity.Size.Id; pet.sub_species_id = petEntity.SubSpecies.Id; if (petEntity.Breed != null) { pet.breed_id = petEntity.Breed.Id; } if (petEntity.Sex == EnumSex.Female) { pet.pet_sex = "F"; } if (petEntity.Sex == EnumSex.Male) { pet.pet_sex = "M"; } if (petEntity.Sex == EnumSex.Other) { pet.pet_sex = null; } pet.date_insert = DateTime.Now; db.petz_Pets.Add(pet); db.SaveChanges(); int petId = pet.pet_id; if (petEntity.ClientId > 0) { db.petz_Client_Pet.Add(new petz_Client_Pet() { pet_id = petId, client_id = petEntity.ClientId }); db.SaveChanges(); } } else { //update Boolean isPetClient = false; if (petEntity.ClientId > 0) { isPetClient = db.petz_Client_Pet.Count(x => x.pet_id == petEntity.Id && x.client_id == petEntity.ClientId) == 1; } if (isPetClient) { //Update petz_Pets pet = db.petz_Pets.FirstOrDefault(x => x.pet_id == petEntity.Id); if (pet != null) { if (userId != null && userId > 0) { pet.update_user_id = userId.Value; } else { pet.update_client_id = petEntity.ClientId; } pet.pet_birthday = petEntity.Birthday; pet.pet_color = petEntity.Color; pet.pet_document = petEntity.Document; pet.pet_name = petEntity.Name; pet.pet_nickname = petEntity.NickName; pet.pet_profile_facebook = petEntity.Facebook; pet.pet_weight = petEntity.Weight; pet.size_id = petEntity.Size.Id; pet.sub_species_id = petEntity.SubSpecies.Id; if (petEntity.Breed != null) { pet.breed_id = petEntity.Breed.Id; } if (petEntity.Sex == EnumSex.Female) { pet.pet_sex = "F"; } if (petEntity.Sex == EnumSex.Male) { pet.pet_sex = "M"; } if (petEntity.Sex == EnumSex.Other) { pet.pet_sex = null; } pet.date_update = DateTime.Now; db.SaveChanges(); } } else { throw new ArgumentOutOfRangeException("petEntity.Id", "This Pet is not of this client"); } } } }