/// <summary> /// Creates a new UserPet. /// </summary> /// <param name="user">Object of the User</param> /// <param name="pet">Object of the Pet</param> /// <returns>Object of the created UserPet</returns> public async Task <UserPet> CreateUserPet(User user, Pet pet) { if (user == null || pet == null) { return(null); } var userPet = new UserPet { DateOfBirth = DateTimeOffset.UtcNow, Happiness = 100, Hunger = 0, LastUpdate = DateTimeOffset.UtcNow, User = user, Pet = pet }; await petGameDb.UserPets.AddAsync(userPet); await petGameDb.SaveChangesAsync(); return(userPet); }
/// <summary> /// Creates a new Pet /// </summary> /// <param name="name">String of the pet name</param> /// <param name="hungerRatio">int of the ratio that the hunger will increase</param> /// <param name="happinessRatio">int of the ratio that the happiness will decrease</param> /// <returns>Object of the created Pet</returns> public async Task <Pet> CreatePet(string name, int hungerRatio, int happinessRatio) { if (string.IsNullOrEmpty(name)) { Console.WriteLine($"{nameof(PetRepository)} - CreatePet - Name can't be null or empty"); return(null); } var pet = new Pet { HappinessRatio = happinessRatio, HungerRatio = hungerRatio, Name = name }; await petGameDb.Pets.AddAsync(pet); await petGameDb.SaveChangesAsync(); return(pet); }
/// <summary> /// Creates a user. /// </summary> /// <param name="name">String of the user name</param> /// <returns>Object of the user created</returns> public async Task <User> CreateUser(string name) { if (string.IsNullOrEmpty(name)) { return(null); } var user = new User() { Created = DateTimeOffset.UtcNow, Name = name }; await petGameDb.Users.AddAsync(user); await petGameDb.SaveChangesAsync(); return(user); }
/// <summary> /// Create a new action on the database. /// </summary> /// <param name="userPet">UserPet object</param> /// <param name="actionType">ActionType enum</param> /// <returns>Object for the created action</returns> public async Task <Action> CreateAction(UserPet userPet, ActionTypeEnum actionType) { if (userPet == null) { Console.WriteLine($"{nameof(ActionRepository)} - CreateAction - BadRequest - Null UserPet"); return(null); } var action = new Action { ActionType = actionType, UserPet = userPet, Date = DateTimeOffset.UtcNow }; await petGameDb.Actions.AddAsync(action); await petGameDb.SaveChangesAsync(); return(action); }