Exemplo n.º 1
0
        private CakeListItemViewModel TransformToListItem(CakeDto cakeDto)
        {
            var listItem = CakeListItemViewModel.TransformToListItem(cakeDto,
                                                                     _appUserModelService.FavouriteCakes.Lookup(cakeDto.Id).HasValue);

            return(listItem);
        }
Exemplo n.º 2
0
        public void AddToFavorites(int cakeId, CakeDto cake)
        {
            var hasCake = _favouriteCakes.Lookup(cakeId);

            if (!hasCake.HasValue)
            {
                _favouriteCakes.AddOrUpdate(cake);
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> AddCake(CakeDto cakeDto)
        {
            if (!ModelState.IsValid)
            {
                var category = await _categoryRepository.GetCategories();

                return(View(new CakeCreateUpdateViewModel
                {
                    CakeDto = cakeDto,
                    Categories = category
                }));
            }
            var cake = _mapper.Map <CakeDto, Cake>(cakeDto);
            await _cakeRepository.AddCakeAsync(cake);

            await _unitOfWork.CompleteAsync();

            return(RedirectToAction("ManageCakes"));
        }
Exemplo n.º 4
0
        public IHttpActionResult CreateCake(CakeDto cakedto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }


            var cake = Mapper.Map <CakeDto, Cake>(cakedto);

            cake.InStock = cake.InStock;
            _context.Cakes.Add(cake);


            _context.SaveChanges();

            cakedto.Id = cake.Id;

            return(Created(new Uri(Request.RequestUri + "/" + cake.Id), cakedto));
        }
Exemplo n.º 5
0
        public IHttpActionResult CreateMovie(CakeDto moviedto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }


            var movie = Mapper.Map <CakeDto, Movie>(moviedto);

            movie.AvailableInStockNow = movie.InStock;
            _context.Movies.Add(movie);


            _context.SaveChanges();

            moviedto.Id = movie.Id;

            return(Created(new Uri(Request.RequestUri + "/" + movie.Id), moviedto));
        }
Exemplo n.º 6
0
        public HttpResponseMessage UpdateMovie(int id, CakeDto cake)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            var checkcake = _context.Movies.SingleOrDefault(c => c.Id == id);

            if (checkcake == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            Mapper.Map <CakeDto, Movie>(cake, checkcake);
            //            checkmovie.Name = customer.Name;
            //            checkmovie.ReleaseDate = movie.ReleaseDate;
            //            checkmovie.GenreId = movie.GenreId;
            //            checkmovie.InStock = movie.InStock;

            _context.SaveChanges();
            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
        public async Task <ActionResult <Cake> > PostCake(CakeDto cakeDto)
        {
            var cake = new Cake(
                cakeDto.Id,
                cakeDto.Name,
                cakeDto.Description,
                cakeDto.ImageUrl,
                cakeDto.Price
                );

            var category = await context.Categories.FirstOrDefaultAsync(c => c.Id == cakeDto.CategoryId);

            cake.Categories.Add(category);

            context.Cakes.Add(cake);
            await context.SaveChangesAsync();

            var cakedto = ToCakeDto(cake);

            return(CreatedAtAction("GetCake", new { id = cakedto.Id }, cakedto));
        }
        public async Task <IActionResult> PutCake(int id, CakeDto cakeDto)
        {
            if (id != cakeDto.Id)
            {
                return(BadRequest());
            }

            var cake = new Cake(
                cakeDto.Id,
                cakeDto.Name,
                cakeDto.Description,
                cakeDto.ImageUrl,
                cakeDto.Price
                );

            //var category = await context.Categories.FirstOrDefaultAsync(c => c.Id == cakeDto.CategoryId);
            //cake.Categories.Add(category);

            context.Entry(cake).State = EntityState.Modified;

            try
            {
                await context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CakeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 9
0
        private CakeOrderListItemViewModel TransformToListItem(CakeDto cakeDto)
        {
            var listItem = CakeOrderListItemViewModel.TransformToListItem(cakeDto);

            return(listItem);
        }
Exemplo n.º 10
0
 public void RemoveFromShoppingBag(CakeDto cake)
 {
     _shoppingBag.Edit(l => l.Remove(cake));
 }
Exemplo n.º 11
0
 public void AddToShoppingBag(CakeDto cake)
 {
     _shoppingBag.Edit(l => l.Add(cake));
 }