void initDishs() { DishTypeService typeService = new DishTypeService(); DishService dishService = new DishService(); List <DishType> typeList = typeService.GetList(); List <Dish> allDish = new List <Dish>(); foreach (DishType type in typeList) { List <Dish> dishList = dishService.GetListByTypeId(type.Id); if (dishList != null) { allDish.AddRange(dishList); } DishAndTypeList.Add(new DishModel { DishType = type, DishList = dishList }); } DishType defautType = new DishType() { Id = "0", Name = "所有" }; DishAndTypeList.Insert(0, new DishModel() { DishType = defautType, DishList = allDish }); }
public async Task <DishType> Post(DishType newType) { _context.DishType.Add(newType); await _context.SaveChangesAsync(); return(newType); }
/// <summary> /// 根据单品食品类型获取信息 /// </summary> /// <param name="type">类型</param> /// <returns></returns> public Result <PageList <Dish> > SearchDishInfoByType(DishType type, PageSearchParam param) { Result <PageList <Dish> > result = new Result <PageList <Dish> >() { Data = null, Status = true }; param.SearchCode = type.GetHashCode().ToString(); param.SearchType = 3; result.Data = new PageList <Dish>(); result.Data.PageIndex = param.PageIndex; result.Data.PageNumer = param.PageNumer; try { //查询符合条件的数据总条数 result.Data.Count = DBConnectionManager.Instance.Reader.Count(new DishCountForSelectPageSpefication(param).Satifasy()); //查询数据集合 IList <DishInfo> dish = DBConnectionManager.Instance.Reader.Select <DishInfo>(new DishSelectPagesPefication(param).Satifasy()); result.Data.List = dish.CopyList <DishInfo, Dish>(); } catch (Exception ex) { result.Status = false; result.Message = "查询单品食物出错:" + ex.Message; result.StatusCode = "SD001"; LoggerUtils.LogIn(LoggerUtils.ColectExceptionMessage(ex, "At service:SearchDishInfoByType() .DishService"), LogType.ErrorLog); } return(result); }
public async Task <IActionResult> Create([Bind("Dish, Dish.Name, Dish.Course, Ingredients, Dish.DishTypeID, SubTypeID, Dish.Recipe, Dish.Price")] DishTypesViewModel dishTypeViewModel) { //HEAD if (ModelState.IsValid) { // Create new Dishtype and assign properties DishType model = new DishType { Name = dishTypeViewModel.Dish.Name, Course = dishTypeViewModel.Dish.Course, Recipe = dishTypeViewModel.Dish.Recipe, Price = dishTypeViewModel.Dish.Price }; var sdt = await repo.GetSubDishTypeID(dishTypeViewModel); if (sdt == null) { return(NotFound()); } model.SubDishType = sdt; repo.InsertDishType(model); await repo.Save(); int id = model.DishTypeID; return(RedirectToAction(nameof(Edit), new { id })); } return(View(dishTypeViewModel)); }
public override DishType GetDish(DishType t) { cookingResult = "Empty"; isCooking = false; ProtectTimer.Change(0, 0); return(base.GetDish(t)); }
public async Task <DishType> Put(DishType updateType) { _context.Update(updateType); await _context.SaveChangesAsync(); return(updateType); }
/// <summary> /// 数据库伪删除 /// </summary> /// <param name="dt">要删除的数据</param> /// <returns>影响行数</returns> public int Drop(DishType dt) { string sql = "Update DishTypeInfo set DIsDelete=1 Where DId=@Id"; //脚本 SQLiteParameter p = new SQLiteParameter("@Id", dt.DId); //参数 return(SQLiteHelper.ExecuteNonQuery(sql, p)); //执行 }
public async Task <ActionResult <DishType> > PostDishType(DishType dishType) { _context.DishTypes.Add(dishType); await _context.SaveChangesAsync(); return(CreatedAtAction("GetDishType", new { id = dishType.Id }, dishType)); }
public async Task <IActionResult> AddIngredientToDish(int IngredientTypeID, int DishTypeID) { Ingredient ingredient = new Ingredient(); DishType P = await repo.GetDishTypeID(DishTypeID); if (P == null) { return(NotFound()); } IngredientType T = await repo.GetIngredientTypeID(IngredientTypeID); if (T == null) { return(NotFound()); } await repo.GetIngredients(); ingredient.Type = T; if (P.DefaultIngredients == null) { P.DefaultIngredients = new List <Ingredient>(); } P.DefaultIngredients.Add(ingredient); await repo.Save(); return(RedirectToAction("Edit", new { id = DishTypeID })); }
public void Should_not_update_a_dish_when_the_dish_name_is_null() { //arrange const DishType dishType = DishType.Drink; const string dishName = default(string); const TimeOfDayType timeOfDay = TimeOfDayType.Morning; const int nextAmountToAdd = 2; var dishes = new Dictionary <(DishType, string), int> { { (dishType, dishName), 1 } }; var dishesMenuServiceFake = A.Fake <IDishesMenuService>(); A.CallTo(() => dishesMenuServiceFake.IsValidAmount( timeOfDay, dishType, nextAmountToAdd) ).Returns(false); var inputProcessorService = new InputProcessorService(dishesMenuServiceFake); //act var dishAddedOrUpdated = inputProcessorService.TryAddOrUpdateDishesAmount( dishes, timeOfDay, dishType, dishName ); //assert dishAddedOrUpdated.Should().BeFalse("Because when the dish name is null it's considered a error"); }
/// <summary> /// 批量保存 /// </summary> /// <param name="child"></param> private void SaveBatch(DishType child) { ICollection <Dish> dishes = child.Dish; if (dishes != null && dishes.Count > 0) { foreach (var dish in dishes) { //获取菜品下说有的做法 List <DischesWayRef> dwrs = _DataService.QueryAllByDishesId(dish.DishId); foreach (var selectedItem in DishesWaySelectedItems) { //根据小类id查找所有的菜品 //插入到做法关联表中 bool flag = true; foreach (var dwr in dwrs) { //判断是否已然存在 if (selectedItem.DischesWayId == dwr.DischesWayId) { flag = false; break; } } if (flag) { _DataService.Add(dish.DishId, selectedItem.DischesWayId); } } } } }
public void Should_add_the_dish_when_this_is_the_first() { //arrange var dishes = new Dictionary <(DishType, string), int>(); const TimeOfDayType timeOfDay = TimeOfDayType.Morning; const DishType dishType = DishType.Drink; var dish = new Dish("coffee", AllowedOrderType.Multiple); var dishesMenuServiceFake = A.Fake <IDishesMenuService>(); A.CallTo(() => dishesMenuServiceFake.IsValidAmount(timeOfDay, dishType, 1)).Returns(true); var inputProcessorService = new InputProcessorService(dishesMenuServiceFake); //act var dishAddedOrUpdated = inputProcessorService.TryAddOrUpdateDishesAmount( dishes, timeOfDay, dishType, dish.Name ); //assert dishAddedOrUpdated.Should().BeTrue("Because the dish allow multiple orders, the rule will be satisfied and should be added"); }
public void Should_not_update_a_dish_when_the_name_already_exists_and_disallow_multiple_orders() { //arrange const DishType dishType = DishType.Drink; var dish = new Dish("eggs", AllowedOrderType.Single); const TimeOfDayType timeOfDay = TimeOfDayType.Morning; const int nextAmountToAdd = 2; var dishes = new Dictionary <(DishType, string), int> { { (dishType, dish.Name), 1 } }; var dishesMenuServiceFake = A.Fake <IDishesMenuService>(); A.CallTo(() => dishesMenuServiceFake.IsValidAmount( timeOfDay, dishType, nextAmountToAdd) ).Returns(false); var inputProcessorService = new InputProcessorService(dishesMenuServiceFake); //act var dishAddedOrUpdated = inputProcessorService.TryAddOrUpdateDishesAmount( dishes, timeOfDay, dishType, dish.Name ); //assert dishAddedOrUpdated.Should().BeFalse("Because the dish disallow multiple orders, the rule will not be satisfied"); }
public DishTypeDto DTFromEF(DishType type) { return(new DishTypeDto() { Description = type.Description, ID = type.ID, Name = type.Name }); }
public ActionResult Edit(DishType dishType) { client = new FireSharp.FirebaseClient(config); SetResponse response = client.Set("DishType/" + dishType.DishType_ID, dishType); return(RedirectToAction("Index")); }
public DishType LoadFatherTypeById(int Id) { try { using (ChooseDishesEntities entities = new ChooseDishesEntities()) { DishType fatherType; DishType type; type = (DishType)entities.DishType.Include("Dish").Where(info => info.DishTypeId == Id); if (type == null) { fatherType = new DishType(); return(fatherType); } fatherType = (DishType)entities.DishType.Include("Dish").Where(info => info.DishTypeId == type.ParentId); if (fatherType == null) { fatherType = new DishType(); } return(fatherType); }; } catch (Exception e) { throw e; } }
public async Task <ActionResult> DeleteDishType(int id) { try { if (id <= 0) { return(BadRequest()); } if (!await _unitOfWork.DishTypes.IsExist(s => s.DishTypeID == id)) { return(NotFound()); } bool result = await DeleteDishes(id); if (!result) { return(BadRequest()); } DishType dishType = await _unitOfWork.DishTypes.FindById(id); _unitOfWork.DishTypes.Delete(dishType); await _unitOfWork.CommitAsync(); return(Ok(dishType)); } catch (Exception) { _unitOfWork.Dispose(); return(BadRequest()); } }
public async Task <IActionResult> Create([FromBody] DishType dish) { if (dish.Name == null) { var ex = new ArgumentException($"{nameof(dish)} can`t be null"); _logger.LogError(ex.ToString()); throw ex; } if (!_validator.Validate(dish).IsValid) { var ex = new ArgumentException($"{nameof(dish)} is not valid"); _logger.LogError(ex.ToString()); throw ex; } try { _dishTypeRepository.Add(dish); await _unitOfWork.SaveChangesAsync(); return(Ok(dish)); } catch (Exception ex) { ex.Data["dish"] = dish; _logger.LogError(ex.ToString()); throw ex; } }
public async Task <IActionResult> PutDishType(int id, DishType dishType) { if (id != dishType.Id) { return(BadRequest()); } _context.Entry(dishType).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DishTypeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> RemoveById(int id) { if (id == default) { var ex = new ArgumentException($"{nameof(id)} can`t be 0"); _logger.LogError(ex.ToString()); throw ex; } try { DishType dishType = await _dishTypeRepository.Get(e => e.Id == id); _dishTypeRepository.Remove(dishType); await _unitOfWork.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { ex.Data["id"] = id; _logger.LogError(ex.ToString()); throw ex; } }
public DishInstance(GameObject instance, DishType type) { Instance = instance; Type = type; _renderer = instance.GetComponent <Renderer>(); _rigidBody = instance.GetComponent <Rigidbody2D>(); }
public Dish(int dishID, int foodID, DishType dishType, TimeOfDay timeOfDay) { DishID = dishID; FoodID = foodID; DishType = dishType; TimeOfDay = timeOfDay; }
public Dish(double x_t, double y_t, DishType type_t) : base(x_t, y_t, ObjType.Dish) { Layer = ItemLayer; Movable = true; Bouncable = true; AddToMessage(); Dish = type_t; this.StopMoving += new StopMovingHandler((o) => { Server.ServerDebug(this + "has stopped moving"); Layer = ItemLayer; if (WorldMap.Grid[(int)Position.x, (int)Position.y].ContainsType(typeof(RubbishBin))) { Parent = null; } }); MoveComplete += ChangePositionInMessage; PositionChangeComplete += ChangePositionInMessage; OnParentDelete += DeleteFromMessage; OnParentDelete += () => { MoveComplete -= ChangePositionInMessage; PositionChangeComplete -= ChangePositionInMessage; }; Server.ServerDebug("Create " + this); }
void DestroyDish() { //Debug.Log("destroy dish called"); Destroy(dish); dish = null; oldDishType = DishType.DishEmpty; }
public Menu(DishType DishType, DrinkSize DrinkSize, DessertType DessertType = DessertType.Normal, bool HasCoffee = false) { this.DishType = DishType; this.DrinkSize = DrinkSize; this.DessertType = DessertType; this.HasCoffee = HasCoffee; }
public async Task <IActionResult> Edit(int id, [Bind("DishTypeId,DishTypeName")] DishType dishType) { if (id != dishType.DishTypeId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(dishType); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DishTypeExists(dishType.DishTypeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(dishType)); }
public Dish[] GetDishes(DishType dishType) { // подготавливаем массив и счетчик для найденных элементов var found = new Dish[this.dishes.Length]; var foundCount = 0; // бежим по массиву блюд foreach (var dish in this.dishes) { // если блюдо имеет нудный тип, ... if (dish.Type == dishType) { // ... то плмещаем его в массив найденных и увеличиваем счетчик на единицу found[foundCount] = dish; foundCount++; } } // создаем массив для результата нужной длинны var result = new Dish[foundCount]; // копируем найденное в результирующий массив Array.Copy(found, result, foundCount); return result; }
public void AddItem(DishType dishType) { switch (dishType) { case DishType.Entree: EntreeCount++; break; case DishType.Side: SideCount++; break; case DishType.Drink: DrinkCount++; break; case DishType.Dessert: DessertCount++; break; default: _invalidDish = true; throw new InvalidEntryException(); } ; }
public override DishType GetDish(DishType t) { DishType temp = Dish; Dish = DishType.DishEmpty; return(temp); }
private void btnSave_Click(object sender, EventArgs e) { DishType dt = new DishType() { DTypeTitle = txtTitle.Text, }; if (btnSave.Text.Equals("添加")) //添加逻辑 { if (dtBll.Add(dt)) { LoadList(); ResetCom(); dr = DialogResult.OK; } else { MessageBox.Show("添加失败,请重试!", "提示"); } } else //修改逻辑 { dt.DId = Convert.ToInt32(txtId.Text); //要修改的数据ID if (dtBll.Edit(dt)) //修改刷新 { LoadList(); ResetCom(); dr = DialogResult.OK; } else { MessageBox.Show("添加失败,请重试!", "提示"); } } }
public static void TaskProduce(object i) { DishType temp = DishType.DishEmpty; for (; ;) { if (Timer.Time.GameTime() < TimeSpan.FromMinutes(10)) { temp = (DishType)Program.Random.Next((int)DishType.TomatoFriedEgg, (int)DishType.SpicedPot); } else { temp = (DishType)Program.Random.Next((int)DishType.TomatoFriedEgg, (int)DishType.SpicedPot + 1); } if (temp == DishType.DishSize1) { continue; } break; } AddTask(temp); RemoveTaskTimer.Add((o, e) => { RemoveTask(temp); }, (uint)Configs[temp.ToString()]["TaskTime"]); //需要广播产生的任务 //感觉只需要广播任务的产生,而任务被完成以及任务因过时而gg都不用广播,需要玩家自己把握? }
/// <summary> /// 数据库添加操作 /// </summary> /// <param name="dt">要添加的数据对象</param> /// <returns>影响行数</returns> public int Insert(DishType dt) { string sql = "Insert into DishTypeInfo(DTitle,DIsDelete) values(@Title,0)"; //语句 SQLiteParameter p = new SQLiteParameter("@Title", dt.DTypeTitle); //参数 return(SQLiteHelper.ExecuteNonQuery(sql, p)); //执行 }
public Dish(String name, DishType type, String image, String description) : this() { Name = name; Type = type; Image = image; Description = description; }
public Dish FindDish(TimeOfDay timeOfDay, DishType dishType) { foreach (var dish in dishList) if (dish.TimeOfDay == timeOfDay && dish.DishType == dishType) return dish; return null; }
public Dish[] GetDishes(DishType dishType, bool isLenten) { // создаем экземпляр делегата с помощью "лямбды" Predicate<Dish> filter = dish => dish.Type == dishType && dish.IsLenten == isLenten; // передаем делегат в стандартный метод и получаем результат return Array.FindAll(this.dishes, filter); }
public IEnumerable<int> GetDishesByType(IEnumerable<int> dishes, DishType dishType) { if (dishType == DishType.Error) { return dishes.Where(d => d != (int)DishType.Entree && d != (int)DishType.Side && d != (int)DishType.Drink); } return dishes.Where(d => d == (int)dishType); }
public Dish[] GetDishes(DishType dishType) { var result = new List<Dish>(); foreach (var dish in this.dishes) { if (dish.Type == dishType) { result.Add(dish); } } return result.ToArray(); }
public int NumOfDishesInDishType(DishType dishType) { if (dishType == DishType.MainCourse) { return NumOfEntree; } else if (dishType == DishType.SideDish) { return 1; } else if (dishType == DishType.Drink) { return 1; } else if (dishType == DishType.NoodleSoup) { return 1; } return 0; }
/// <summary> /// Creates a menu item /// </summary> /// <param name="name">Dish name to be used</param> /// <param name="period">Period where the dish will be avaiable</param> /// <param name="dishType">Type of the dish</param> /// <param name="maxCount">Max number of items on a order</param> /// <returns></returns> private static MenuItem CreateMenuItem(string name, PeriodOfDay period, DishType dishType = DishType.Entree, int maxCount = 1) { return new MenuItem {Dish = new Dish {Name = name }, PeriodOfDay = period , DishType = dishType, MaxOrder = maxCount}; }
public Dish[] GetDishes(DishType dishType, bool isLenten) { Predicate<Dish> filter = dish => dish.Type == dishType && dish.IsLenten == isLenten; return this.dishes.FindAll(filter).ToArray(); }
public Dish(string name, DishType type) { this.Name = name; this.Type = type; }
public Dish(string dishTypeTitle, DishType dishType) { this.dishTypeTitle = dishTypeTitle; this.dishType = dishType; }
public void FilterDishes(DishType type, string filter) { _dinner.GetAllDishes(type, filter); }
public Dish(string name, DishType type) { this.Name = name; this.Type = type; this.ingredients = new List<Ingredient>(); }
private static bool IsValidDishType(DishType? dishType) { return dishType != null; }
public MenuItem GetMenuItem(TimeOfDay timeOfDay, DishType dishType) { MenuItem menuItem = menuItems.FirstOrDefault(x => x.Dish.DishType == dishType && x.TimeOfDay == timeOfDay); return menuItem; }
/// <summary> /// Validates if an item is available in that period /// </summary> /// <param name="dishType"></param> /// <param name="period"></param> /// <returns></returns> private string ValidateItemAvailability(DishType dishType, PeriodOfDay period) { var errorMessage = string.Empty; var isAnInvalidItem = _avaiableDishes.Count(n => n.DishType == dishType && n.PeriodOfDay == period) == 0; if (isAnInvalidItem) { errorMessage = $"{dishType} is not available in this period"; } return errorMessage; }
public Dish[] GetDishes(DishType dishType, bool isLenten) { throw new NotImplementedException(); }