public void GenerateDishData() { var dishes = new DishDto[] { new DishDto { DishType = 1, morning = new DishDescripionDto { Name = "eggs", AllowMultiple = false }, night = new DishDescripionDto { Name = "steak", AllowMultiple = false } }, new DishDto { DishType = 2, morning = new DishDescripionDto { Name = "toast", AllowMultiple = false }, night = new DishDescripionDto { Name = "potato", AllowMultiple = true } }, new DishDto { DishType = 3, morning = new DishDescripionDto { Name = "coffee", AllowMultiple = true }, night = new DishDescripionDto { Name = "wine", AllowMultiple = false } }, new DishDto { DishType = 4, morning = null, night = new DishDescripionDto { Name = "cake", AllowMultiple = false } } }; var stringWriter = new StringWriter(); var serializer = new XmlSerializer(typeof(DishDto[])); serializer.Serialize(stringWriter, dishes); Console.Write(stringWriter.ToString()); }
public IActionResult UpdateDishForCuisine(Guid cuisineId, Guid id, [FromBody] DishDto dish) { if (dish == null) { return(BadRequest()); } if (!_RestaurantRepository.CuisineExists(cuisineId)) { return(NotFound()); } var _dish = _RestaurantRepository.GetDishForCuisine(cuisineId, id); if (_dish == null) { return(NotFound()); } if (dish.Name != null) { _dish.Name = dish.Name; } if (dish.Description != null) { _dish.Description = dish.Description; } if (!_RestaurantRepository.Save()) { throw new Exception("Unable to update this dish."); } return(NoContent()); }
public async Task <bool> UpsertAsync(DishDto dishDto) { var dishValidation = _dishValidator.Validate(dishDto); if (!dishValidation.IsValid) { throw new ArgumentException(dishValidation.Erros.First().Message); } try { var upsertResult = await _dishDao.UpsertAsync(dishDto); if (upsertResult.IsAcknowledged && upsertResult.IsModifiedCountAvailable) { return(true); } _logger.Warning("Upsert dish failed"); return(false); } catch (Exception e) { _logger.Error("Exception when save dish: " + e.Message); return(false); } }
public async Task AddAsync(DishDto dishDto) { var dish = Mapper.Map <Dish>(dishDto); Insert(dish); await Context.SaveChangesAsync(); }
public IActionResult CreateDishForCuisine(Guid cuisineId, [FromBody] DishDto dish) { if (dish == null) { return(BadRequest()); } if (!_RestaurantRepository.CuisineExists(cuisineId)) { return(NotFound()); } var dishNew = new Dish { Id = Guid.NewGuid(), Name = dish.Name, Description = dish.Description, CuisineId = cuisineId }; _RestaurantRepository.AddDishForCuisine(cuisineId, dishNew); if (!_RestaurantRepository.Save()) { throw new Exception($"Creating a new Dish for Cuisine {cuisineId} failed."); } return(CreatedAtRoute("GetDishForCuisine", new{ cuisineId = cuisineId, id = dishNew.Id }, dishNew)); }
public async Task <IStatusCodeActionResult> Create(DishDto dishDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { if (await _dishRepository.UpsertAsync(dishDto)) { return(Accepted()); } return(BadRequest()); } catch (ArgumentException exception) { return(BadRequest(exception.Message)); } catch (Exception e) { return(BadRequest(e.Message)); } }
private async Task ParseDishTitles(HtmlNodeCollection dishTitles, string menuLink, string menuName, string menuDescription, string menuTitleText, ConcurrentBag <DishDto> dishes) { if (dishTitles == null) { return; } var loadDescriptionTasks = new List <Task>(); foreach (var dishTitle in dishTitles) { var dish = new DishDto() { MenuTitle = menuName, MenuDescription = menuDescription, // to do: create a wrapper around dish dto with a task member that will allow parallel description extractions //DishDescription = await ExtractDishDescriptionAsync(ConstructUrl(menuLink, dishTitle.Attributes["href"].Value)), DishName = dishTitle.Attributes["title"].Value, MenuSectionTitle = menuTitleText }; loadDescriptionTasks.Add(Task.Run(async() => dish.DishDescription = await ExtractDishDescriptionAsync(ConstructUrl(menuLink, dishTitle.Attributes["href"].Value)))); dishes.Add(dish); Logger.LogInformation($"New dish {dish.DishName} created"); } Task.WaitAll(loadDescriptionTasks.ToArray()); }
public async Task UpdateAsync(DishDto dishDto) { var dish = Mapper.Map <Dish>(dishDto); Update(dish); await Context.SaveChangesAsync(); }
//Add public void AddDish(DishDto dish) { var dissh = new Dish { Name = dish.Name, Description = dish.Description, Price = dish.Price, PriceDelivery = dish.PriceDelivery, DishTypeId = dish.TypeId, Image = dish.Image }; _dishRepository.Add(dissh); }
public void Should_Satisfied_When_PriceIsValid( DishDto dto, bool expectResult ) { var priceIsValidSpecification = new PriceIsValidSpecification(); Assert.AreEqual(expectResult, priceIsValidSpecification.IsSatisfiedBy(dto)); }
public void Should_Satisfied_When_RestaurantIdIsValid( DishDto dto, bool expectResult ) { var validSpecification = new RestaurantIdIsValidSpecification(); Assert.AreEqual(expectResult, validSpecification.IsSatisfiedBy(dto)); }
public void Should_Satisfied_When_AwaitingTimeIsValid( DishDto dto, bool expectResult ) { var awaitingTimeIsValidSpecification = new AwaitingTimeIsValidSpecification(); Assert.AreEqual(expectResult, awaitingTimeIsValidSpecification.IsSatisfiedBy(dto)); }
public ActionResult <DishDto> CreateDish(DishDto dishDto) { var dishModel = _mapper.Map <Dish>(dishDto); _repository.CreateDish(dishModel); var newDishDto = _mapper.Map <DishDto>(dishModel); return(CreatedAtRoute(nameof(GetDishById), new { Id = newDishDto.Id }, newDishDto)); }
public IActionResult Put([FromBody] DishDto dishDto, int id) { var dish = _dishService.UpdateProgramDish(dishDto, id); if (dish == null) { return(BadRequest()); } return(NoContent()); }
private static DishDto InterfaceToDto(IDish dish) { var dishDto = new DishDto { Id = dish.Id, Name = dish.Name, ArticleDishes = dish.ArticleDishes }; return(dishDto); }
public Dish AddNewProgramDish(DishDto dto) { var dish = new Dish { Name = dto.Name, TypeOfMeal = dto.TypeOfMeal }; _dishRepository.Add(dish); _dishRepository.Save(); return(dish); }
//Display dish info public ActionResult ViewDish(int id) { DishDto dish = dishService.GetDishByID(id); //var e = ingredientService.GetIngredientByName("Tomato"); var viewModel = new DishViewModel { Description = dish.Description, Name = dish.Name, Price = dish.Price, ID = dish.DishID }; return(View(viewModel)); }
private Dish DtoToDish(DishDto dto) { return(new Dish() { Id = dto.Id, ClientId = dto.ClientId, Description = dto.Description, Name = dto.Name, Price = dto.Price, Rate = dto.Rate, Type = dto.Type }); }
public void ItIsTransformedFromADtoWithOnlyMorningDefined() { const string morningDishName = "duck confit"; //Need to create a real DTO as reflection does not play nicely with MOQ due to dynamic castle proxy. var dishDto = new DishDto { morning = new DishDescripionDto { AllowMultiple = true, Name = morningDishName } }; var actual = _dishFactory.Transform(dishDto); Assert.That(actual.NameAtMealTime["morning"], Is.EqualTo(morningDishName)); Assert.That(actual.MultipleAtMealTime["morning"], Is.True); Assert.That(actual.NameAtMealTime, Is.Not.Contains("night")); Assert.That(actual.MultipleAtMealTime, Is.Not.Contains("night")); }
public Dish UpdateProgramDish(DishDto dto, int id) { var dish = _dishRepository.Find(id); if (dish == null) { return(null); } dish.Name = dto.Name; dish.TypeOfMeal = dto.TypeOfMeal; _dishRepository.Save(); return(dish); }
public ActionResult SaveDish(SaveDishViewModel dish) { if (!ModelState.IsValid) { var dishViewModel = new SaveDishViewModel() { DishDto = dish.DishDto, Ingredients = ingredientService.GetAllIngredients().ToList(), DishTypeDtos = dishService.GetAllDishTypes().ToList() }; return(View("SaveDishForm", dishViewModel)); } try { if (dish.DishDto.DishID == 0) { DishDto newDish = new DishDto() { Name = dish.DishDto.Name, Description = dish.DishDto.Description, CreatedOn = DateTime.Now, Price = dish.DishDto.Price, IsActive = true, DishType = dish.DishDto.DishType, Ingredients = dish.Ingredients.Where(ing => ing.IsSelected).ToList() }; dishService.CreateNewDish(newDish); return(RedirectToAction("Index")); } //edit dish DishDto editDishDto = new DishDto() { DishID = dish.DishDto.DishID, Name = dish.DishDto.Name, Description = dish.DishDto.Description, Price = dish.DishDto.Price, DishType = dish.DishDto.DishType, Ingredients = dish.Ingredients.Where(ing => ing.IsSelected).ToList(), }; dishService.UpdateDish(editDishDto); return(RedirectToAction("Index")); } catch (NullReferenceException e) { return(new HttpStatusCodeResult(500)); } }
public async Task CreateDish_WithDisBom_Test() { await _foodMaterialAppService.Create(new FoodMaterialDto() { Description = "foodMaterial001" }); var foodMaterial = _foodMaterialAppService.GetAll(new FoodMateialPagedResultRequestDto { MaxResultCount = 20, SkipCount = 0 }) .Result.Items[0]; DishBomDto bom = new DishBomDto() { Id = 1, FoodMaterialId = foodMaterial.Id, }; DishDto dish = new DishDto { Description = "johnNash", DishBoms = new List <DishBomDto>() { bom } }; // Act var dtoTemp = await _appService.Create(dish); await UsingDbContextAsync(async context => { var johnNashDish = await context.Dish.FirstOrDefaultAsync(u => u.Description == "johnNash"); johnNashDish.ShouldNotBeNull(); }); var output = await _appService.GetAll(new SortSearchPagedResultRequestDto { MaxResultCount = 20, SkipCount = 0 }); output.Items.Count.ShouldBeGreaterThan(0); var dishOutput = output.Items[0]; dishOutput.ShouldNotBeNull(); dishOutput.DishBoms.ShouldNotBeNull(); dishOutput.DishBoms.Count.ShouldBeGreaterThan(0); Console.WriteLine(output); }
public async Task CreateAsync(DishDto dish) { var origDish = _mapper.Map <DishDto, Dish>(dish); var dishes = await _dishRepository.GetAll(); var isDish = dishes.Any(d => d.Name == dish.Name); if (isDish) { throw new BadRequestException("Dish with the same name is exist."); } await _dishRepository.Create(origDish); }
public ActionResult UpdateDish(int id, DishDto dishDto) { var dishFromRepo = _repository.GetDishById(id); dishDto.Id = dishFromRepo.Id; if (dishFromRepo == null) { return(NotFound()); } _mapper.Map(dishDto, dishFromRepo); _repository.UpdateDish(dishFromRepo); return(NoContent()); }
public ServiceResponse <bool> Update(DishDto dto) { var result = new ServiceResponse <bool>(); try { var entity = _service.Get(dto.IdDish); if (entity != null) { var restaurant = _serviceRestaurant.Get(dto.IdRestaurant); if (restaurant != null) { entity.Modify(dto.Name, restaurant, dto.Price); if (entity.Valid) { result.Result = result.Object = _service.Update(entity); if (!result.Result) { ((Notifiable)_service).Notifications .ToList() .ForEach(x => result.Messages.Add(x.Message)); } } else { entity.Notifications.ToList().ForEach(x => result.Messages.Add(x.Message)); } } else { result.Messages.Add("The restaurant informed in the request don't exists in th system"); } } else { result.Messages.Add("Can't find the dish to modify"); } } catch (Exception ex) { result.Messages.Add("Problems when try to update the dish: " + ex.Message); } return(result); }
public IEnumerable <Dish> Convert(DishDto source, IEnumerable <Dish> destination, ResolutionContext context) { List <Tuple <int, decimal> > tuples = new List <Tuple <int, decimal> >(); for (int i = 0; i < 3; i++) { tuples.Add( new Tuple <int, decimal>( source.Weights.ElementAt(i), source.Prices.ElementAt(i))); } foreach (var dish in tuples.Select(tup => context.Mapper.Map <Dish>(tup))) { context.Mapper.Map(source, dish); yield return(dish); } }
public Dish FromPOCO(DishDto dish) { Dish d = new DAL.Entities.Dish() { ID = dish.DishID, CreatedOn = dish.CreatedOn, Description = dish.Description, IsActive = dish.IsActive, TypeID = dish.DishType, Name = dish.Name, Price = (decimal)dish.Price, Orders = new List <Order>(), Ingredients = new List <Ingredient>(), Images = new List <Image>() }; if (dish.Ingredients.Count > 0) { foreach (var v in dish.Ingredients) { if (v == null) { continue; } var ing = unitOfWork.IngredientsRepository.GetByID(v.ID); if (ing != null) { d.Ingredients.Add(ing); } } } if (dish.ImagesId.Count > 0) { dish.ImagesId.ForEach(x => { var img = unitOfWork.ImagesRepository.GetByID(x); if (img != null) { d.Images.Add(img); } }); } return(d); }
public IActionResult SaveDish([FromBody] DishDto dto) { try { if (ModelState.IsValid) { var dish = DtoToDish(dto); _unitOfWork.dishes.Insert(dish); _unitOfWork.Save(); return(Created("AskxammiApi/SaveDish", dish)); } else { return(BadRequest()); } } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public IActionResult UpdateDish([FromBody] DishDto dto) { try { if (ModelState.IsValid) { var dish = DtoToDish(dto); _unitOfWork.dishes.Update(dish); _unitOfWork.Save(); return(Ok()); } else { return(BadRequest()); } } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public DishDto FromEF(Dish d) { if (d == null) { return(null); } var retval = new DishDto() { DishID = d.ID, Ingredients = new List <IngredientDto>(), IsActive = d.IsActive, Price = d.Price, CreatedOn = d.CreatedOn, Description = d.Description, DishType = d.TypeID, DishTypeName = d.Type.Name, Name = d.Name, ImagesId = d.Images.Select(x => x.ImageID).ToList() }; retval.Ingredients.AddRange(GetIngredientsForDish(d.ID)); return(retval); }