private void WaterPlantQuestion(List <UserPlant> list) { Header("Vattna"); Console.WriteLine(); foreach (var plant in list) { WriteLine("Id: " + plant.UserPlantId); WriteLine("Namn: " + plant.Name); } Console.WriteLine(); WriteLine("Vilken Planta vill du Vattna?"); int uppdPlant = int.Parse(Console.ReadLine()); UserPlant PlantToWater = SortOutUserPlant(list, uppdPlant); Console.Clear(); Console.WriteLine(); Console.BackgroundColor = ConsoleColor.DarkGreen; WriteLine("Vattnar blomman..."); Console.ResetColor(); Console.ReadKey(); PlantToWater.LastWatered = DateTime.Now; _dataAccess.UpdateUserPlant(PlantToWater); Console.ReadKey(); SeeUserPlantsMenu(); }
public IActionResult Create([FromBody] UserPlantCreateViewModel model) { if (!ModelState.IsValid) { return(UnprocessableEntity(new ValidationErrorModel(ModelState))); } PlantType type = _plantData.GetPlantType(model.PlantTypeID); UserPlant plant = new UserPlant { OwnerID = model.OwnerID, NickName = model.NickName, WherePurchased = model.WherePurchased, PlantType = type, LastWatered = model.LastWatered, WaterAgain = GetNextWater(model.LastWatered, type), LastFertalized = model.LastFertalized, FertalizeAgain = GetNextFeed(model.LastFertalized, type), Birtdhday = model.Birthday, IsDeleted = false, ReceiveNotifications = model.ReceiveNotifications, IsFavorite = false, PrimaryImageID = model.PrimaryImageID ?? type.StockImageID }; _plantData.Add(plant); _plantData.Commit(); return(Created("", new UserPlantDisplayViewModel(plant))); }
public IActionResult Update(int id, [FromBody] UserPlantUpdateViewModel model) { UserPlant plant = _plantData.Get(id); if (plant == null) { return(NotFound()); } if (!ModelState.IsValid) { return(UnprocessableEntity(new ValidationErrorModel(ModelState))); } PlantType plantType = _plantData.GetPlantType(model.TypeID); plant.NickName = model.NickName; plant.WherePurchased = model.WherePurchased; plant.PlantType = plantType; plant.ReceiveNotifications = model.ReceiveNotifications; plant.IsFavorite = model.IsFavorite; plant.PrimaryImageID = model.PrimaryImageID; UserPlantDisplayViewModel updated = new UserPlantDisplayViewModel(plant); _plantData.Update(plant); _plantData.Commit(); return(Ok(updated)); }
//开启种植功能 public static void GetUserLand(string userID) { UserPlant plant = new PersonalCacheStruct <UserPlant>().FindKey(userID); if (plant == null) { UserPlant userPlant = new UserPlant() { UserID = userID, LandNum = 1, DewNum = ConfigEnvSet.GetInt("UserQueue.ShengShuiMaxNum"), PayDewTime = 0, }; new PersonalCacheStruct <UserPlant>().Add(userPlant); } int postion = 1; UserLand land = new PersonalCacheStruct <UserLand>().FindKey(userID, postion); if (land == null) { UserLand userLand = new UserLand() { UserID = userID, LandPositon = postion, IsRedLand = 2, IsBlackLand = 2, IsGain = 2, PlantType = PlantType.Experience, PlantQuality = PlantQualityType.PuTong, GeneralID = 0, }; new PersonalCacheStruct <UserLand>().Add(userLand); } }
public static UserPlant Map(IRepository <eSuiteDbContext> repository, SqlDataReader dr) { var entity = new UserPlant(); entity.UserId = LookUpUser(repository, Convert.ToString(dr["U_Login_Id"])); entity.PlantId = Lookups.LookUpPlant(repository, Convert.ToString(dr["cif"])); return(entity); }
public IActionResult Get(int id) { UserPlant plant = _plantData.Get(id); if (plant == null) { this.logger.LogWarning($"Plant number {id} was not found."); return(NotFound()); } return(Ok(new UserPlantDisplayViewModel(plant))); }
public IActionResult Delete(int id) { UserPlant plant = _plantData.Get(id); if (plant == null) { this.logger.LogWarning($"Plant number {id} was not found."); return(NotFound()); } _plantData.Delete(plant); _plantData.Commit(); return(NoContent()); }
private void WaterPlant(UserPlant newUserPlant) { Console.Clear(); Console.WriteLine(); WriteLine("Vattnar blomman..."); Console.ReadKey(); newUserPlant.LastWatered = DateTime.Now; _dataAccess.UpdateUserPlant(newUserPlant); Console.ReadKey(); SeeUserPlantsMenu(); }
private UserPlant SortOutUserPlant(List <UserPlant> list, int UserPlantId) { UserPlant newPlant = new UserPlant(); foreach (var plant in list) { if (plant.UserPlantId == UserPlantId) { newPlant = plant; } else { WriteLine("Nu blev det fel"); } } return(newPlant); }
public void Delete(UserPlantDto entity) { try { UserPlant deleteEntity = _repository.Repository <UserPlant>() .GetAllBy(u => u.PlantId == entity.PlantId && u.UserId == entity.UserId) .First(); _repository.Repository <UserPlant>().Delete(deleteEntity); _repository.Save(); } catch (Exception ex) { LogException(ex); throw; } }
public UserPlant FindPlantOnId(int UserPlantId) { var sql = @" SELECT Plant.Name, Location.Location, UserPlants.WaterFrekuenseInDays, Soil.SoilType, Nutrition.NutritionType, BoughtDate, Comment, UserPlants.UserId, [User].UserName, LastWater FROM UserPlants INNER JOIN Plant ON UserPlants.PlantId=Plant.PlantId INNER JOIN Location ON UserPlants.LocationId=Location.LocationId INNER JOIN Soil ON UserPlants.SoildId=Soil.SoilId INNER JOIN Nutrition ON UserPlants.NutritionId=Nutrition.NutritionId INNER JOIN [User] ON UserPlants.UserId=[User].UserId WHERE UserPlants.UserPlantId=@UserPlantId "; using (SqlConnection connection = new SqlConnection(conString)) using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); command.Parameters.Add(new SqlParameter("UserPlantId", UserPlantId)); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { var up = new UserPlant { UserPlantId = reader.GetSqlInt32(0).Value, Name = reader.GetSqlString(1).Value, Location = reader.GetSqlString(2).Value, WaterFrequence = reader.GetSqlInt32(3).Value, Soil = reader.GetSqlString(4).Value, Nutrition = reader.GetSqlString(5).Value, Bought = reader.GetSqlDateTime(6).Value, UserInfo = reader.GetSqlString(7).Value, UserId = reader.GetSqlInt32(8).Value, UserName = reader.GetSqlString(9).Value, LastWatered = reader.GetSqlDateTime(10).Value, }; return(up); } else { return(null); } } }
public void UpdateUserPlant(UserPlant newUserPlant) { var sql = @"UPDATE UserPlants SET WaterFrekuenseInDays=@WaterFrekuenseInDays, Comment=@Comment, LastWater=@LastWater WHERE UserPlantId=@UserPlantId"; using (SqlConnection connection = new SqlConnection(conString)) using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); command.Parameters.Add(new SqlParameter("UserPlantId", newUserPlant.UserPlantId)); command.Parameters.Add(new SqlParameter("WaterFrekuenseInDays", newUserPlant.WaterFrequence)); command.Parameters.Add(new SqlParameter("Comment", newUserPlant.UserInfo)); command.Parameters.Add(new SqlParameter("LastWater", newUserPlant.LastWatered)); command.ExecuteNonQuery(); } }
public List <UserPlant> ShowAllUserPlantsList() { List <UserPlant> list = new List <UserPlant>(); var sql = @" SELECT UserPlantId, Plant.Name, Location.Location, UserPlants.WaterFrekuenseInDays, Soil.SoilType, Nutrition.NutritionType, BoughtDate, Comment, UserPlants.UserId, [User].UserName FROM UserPlants INNER JOIN Plant ON UserPlants.PlantId=Plant.PlantId INNER JOIN Location ON UserPlants.LocationId=Location.LocationId INNER JOIN Soil ON UserPlants.SoildId=Soil.SoilId INNER JOIN Nutrition ON UserPlants.NutritionId=Nutrition.NutritionId INNER JOIN [User] ON UserPlants.UserId=[User].UserId "; using (SqlConnection connection = new SqlConnection(conString)) using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { var up = new UserPlant { UserPlantId = reader.GetSqlInt32(0).Value, Name = reader.GetSqlString(1).Value, Location = reader.GetSqlString(2).Value, WaterFrequence = reader.GetSqlInt32(3).Value, Soil = reader.GetSqlString(4).Value, Nutrition = reader.GetSqlString(5).Value, Bought = reader.GetSqlDateTime(6).Value, UserInfo = reader.GetSqlString(7).Value, UserId = reader.GetSqlInt32(8).Value, UserName = reader.GetSqlString(9).Value, }; list.Add(up); } return(list); } }
public UserPlantDisplayViewModel(UserPlant plant) { this.PlantId = plant.PlantId; this.OwnerId = plant.OwnerID; this.TypeId = plant.PlantType.PlantTypeID; this.CommonName = plant.PlantType.CommonName; this.LatinName = plant.PlantType.LatinName; this.NickName = plant.NickName; this.WherePurchased = plant.WherePurchased; this.LastWatered = plant.LastWatered; this.WaterAgain = plant.WaterAgain; this.LastFertalized = plant.LastFertalized; this.FertalizeAgain = plant.FertalizeAgain; this.Birtdhday = plant.Birtdhday; this.ReceiveNotifications = plant.ReceiveNotifications; this.IsFavorite = plant.IsFavorite; this.PrimaryImageID = plant.PrimaryImageID; this.LightLevel = plant.PlantType.LightLevel.ToString(); this.Toxisity = GetToxisityAray(plant.PlantType); }
private void UpdateUserPlant(List <UserPlant> list) { Header("Uppdatera planta"); foreach (var plant in list) { WriteLine("Id: " + plant.UserPlantId); WriteLine("Namn: " + plant.Name); } WriteLine("Vilken Planta vill du uppdatera?"); int uppdPlant = int.Parse(Console.ReadLine()); UserPlant PlantToUppdate = SortOutUserPlant(list, uppdPlant); Header("Uppdaterar " + PlantToUppdate.Name); UserPlant newUserPlant = PlantToUppdate; WriteLine("Vad vill du uppdatera?"); WriteLine("a) Placering"); WriteLine("b) Dagar mellan vattning"); WriteLine("c) Uppdatera informationen"); WriteLine("d) Vattna"); WriteLine("e) Ta bort Planta"); WriteLine("f) Tillbaka"); ConsoleKey key2 = Console.ReadKey(true).Key; if (key2 == ConsoleKey.A) { WriteLine("Här kan man uppdatera väderstreck sen"); WriteLine("Uppdaterat!"); Console.ReadKey(); SeeUserPlantsMenu(); } if (key2 == ConsoleKey.B) { Console.WriteLine(); WriteLine("Hur många dagar vill du ha mellan vattning?"); newUserPlant.WaterFrequence = int.Parse(Console.ReadLine()); _dataAccess.UpdateUserPlant(newUserPlant); Console.Clear(); WriteLine("Uppdaterat!"); Console.ReadKey(); SeeUserPlantsMenu(); } if (key2 == ConsoleKey.C) { Console.WriteLine(); WriteLine("Ange ny information om plantan."); newUserPlant.UserInfo = Console.ReadLine(); _dataAccess.UpdateUserPlant(newUserPlant); Console.Clear(); WriteLine("Uppdaterat!"); Console.ReadKey(); SeeUserPlantsMenu(); } if (key2 == ConsoleKey.D) { WaterPlant(newUserPlant); } if (key2 == ConsoleKey.E) { DeleteUserPlant(PlantToUppdate.UserPlantId); } if (key2 == ConsoleKey.F) { SeeUserPlantsMenu(); } else { WriteLine("Nu blev det fel!"); Console.ReadKey(); MainMenu(); } }
public override bool TakeAction() { var cacheSet = new PersonalCacheStruct <UserPlant>(); UserPlant plant = cacheSet.FindKey(ContextUser.UserID); var landCacheSet = new PersonalCacheStruct <UserLand>(); List <UserLand> landArray = landCacheSet.FindAll(ContextUser.UserID); if (plant == null) { UserPlant uPlant = new UserPlant() { UserID = ContextUser.UserID, LandNum = 1, DewNum = ConfigEnvSet.GetInt("UserQueue.ShengShuiMaxNum"), PayDewTime = 0, }; cacheSet.Add(uPlant); } if (landArray.Count == 0) { UserLand userLand = new UserLand() { UserID = ContextUser.UserID, PlantType = PlantType.Experience, LandPositon = 1, IsRedLand = 2, IsBlackLand = 2, IsGain = 2 }; landCacheSet.Add(userLand); } if (new PersonalCacheStruct <UserFunction>().FindKey(ContextUser.UserID, FunctionEnum.Zhongzhijingqianshu) == null) { isShow = 2; } else { isShow = 1; } userPlant = new PersonalCacheStruct <UserPlant>().FindKey(ContextUser.UserID); userLandArray = new PersonalCacheStruct <UserLand>().FindAll(ContextUser.UserID); //圣水恢复 var queueCacheSet = new PersonalCacheStruct <UserQueue>(); List <UserQueue> ShengShuiQueueArray = queueCacheSet.FindAll(ContextUser.UserID, m => m.QueueType == QueueType.ShengShuiHuiFu); if (ShengShuiQueueArray.Count > 0) { UserQueue shengShuiQueue = ShengShuiQueueArray[0]; if (userPlant != null) { int shengshuiMaxNum = ConfigEnvSet.GetInt("UserQueue.ShengShuiMaxNum"); int restorationDate = ConfigEnvSet.GetInt("UserQueue.ShengShuiRestorationDate"); //三小时 int restorationNum = ConfigEnvSet.GetInt("UserQueue.ShengShuiRestorationNum"); //恢复1点 int timeCount = (int)(DateTime.Now - shengShuiQueue.Timing).TotalSeconds / restorationDate; if (userPlant.DewNum < shengshuiMaxNum && timeCount > 0) { userPlant.DewNum = MathUtils.Addition(userPlant.DewNum, (timeCount * restorationNum), shengshuiMaxNum); //userPlant.Update(); shengShuiQueue.Timing = DateTime.Now; //shengShuiQueue.Update(); } } } else { UserQueue queue = new UserQueue() { QueueID = Guid.NewGuid().ToString(), UserID = ContextUser.UserID, QueueType = QueueType.ShengShuiHuiFu, QueueName = QueueType.ShengShuiHuiFu.ToString(), Timing = DateTime.Now, ColdTime = 0, TotalColdTime = 0, IsSuspend = false, StrengNum = 0 }; queueCacheSet.Add(queue); } return(true); }
private void SaveRelatedPlant(UserDto dto, List <int> relatedPlants) { var plants = _repository.Repository <UserPlant>().GetAllBy(f => f.User.ID == dto.Id).ToList(); #region Save New Plants // find all the plants to add foreach (var plantId in relatedPlants) { if (!plants.FindAll(p => p.PlantId == plantId).Any()) { // add it var newPlant = new UserPlant() { PlantId = plantId, UserId = dto.Id, EnteredBy = dto.ModifiedBy, DateEntered = dto.LastModified, ModifiedBy = dto.ModifiedBy, LastModified = dto.LastModified }; try { _repository.Repository <UserPlant>().Insert(newPlant); _repository.Save(); } catch (DbEntityValidationException valEx) { HandleValidationException(valEx); } catch (Exception ex) { LogException(ex); throw; } } } #endregion #region Remove Plants // find all the plants to remove foreach (var existPlant in plants) { if (!relatedPlants.FindAll(p => p == existPlant.PlantId).Any()) { try { _repository.Repository <UserPlant>().Delete(existPlant); _repository.Save(); } catch (Exception ex) { LogException(ex); throw; } } } #endregion }
public void Add(UserPlant plant) { _dbContext.UserPlant.Add(plant); }
public void Update(UserPlant plant) { }
public void Delete(UserPlant plant) { plant.IsDeleted = true; }