Exemplo n.º 1
0
        public void NullStateShouldThrowException()
        {
            ArgumentNullException exception = Assert.Throws <ArgumentNullException>(
                () => Cigar.Load(null));

            Assert.Equal("state", exception.ParamName);
        }
Exemplo n.º 2
0
        public async Task SeedAsync(ApplicationDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (dbContext.Cigars.Any())
            {
                return;
            }

            var list = new List <Cigar>();

            for (int i = 0; i < CigarSeedDataConstants.CigarNameList.Length; i++)
            {
                string brandName = CigarSeedDataConstants.CigarNameList[i].Split(" ")[0];

                var cigar = new Cigar
                {
                    BrandId      = BrandFinder(dbContext, brandName),
                    StrenghtId   = StrenghtFinder(dbContext, CigarSeedDataConstants.StrenghtList[i]),
                    SizeId       = SizeFinder(dbContext, CigarSeedDataConstants.LengthRangeList[i], CigarSeedDataConstants.RingRangeList[i]),
                    TasteId      = TasteFinder(dbContext, CigarSeedDataConstants.TesteList[i]),
                    ShapeId      = ShapeFinder(dbContext, CigarSeedDataConstants.ShapeList[i]),
                    CigarName    = CigarSeedDataConstants.CigarNameList[i],
                    Bland        = "regular",
                    PricePerUnit = CigarSeedDataConstants.UnitPrice[i],
                    ImageUrl     = CigarSeedDataConstants.ImageUrl[i],
                };

                list.Add(cigar);
            }

            await dbContext.AddRangeAsync(list);

            await dbContext.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public async void CreateShouldCallAddNewCigarWithParameterItem()
        {
            var newCigar = new Cigar();
            await controller.Create(newCigar);

            mockCigarService.Verify(x => x.AddNewCigar(newCigar));
        }
Exemplo n.º 4
0
        private async void AddCigarAsync(object sender, EventArgs e)
        {
            Settings.ciggarsToday = Convert.ToString(Convert.ToInt32(Settings.ciggarsToday) + 1);
            //  Debug.WriteLine("1");
            //save database
            Cigar cigar = new Cigar();

            cigar.year  = DateTime.Now.Year;
            cigar.month = DateTime.Now.Month;
            cigar.day   = DateTime.Now.Day;
            cigar.cost  = (double.Parse(Settings.costByPocket, CultureInfo.InvariantCulture) / double.Parse(Settings.ciggarsPerPocket, CultureInfo.InvariantCulture));
            //  Debug.WriteLine("2");
            App.CigarDatabse.SaveCigar(cigar);
            //    Debug.WriteLine("3");
            ActualizarLayout();
            //        Debug.WriteLine("4");
            if (timer == true)
            {
                hora    = 0;
                minutes = 0;
                // stopTimer = false;
                //timer = false;
                // StartTimer();
            }
            else
            {
                StartTimer();
            }
            //    Debug.WriteLine("after add cigar number of cigars:" + Settings.ciggarsToday);
        }
Exemplo n.º 5
0
        public ActionResult AddToCart(int id)
        {
            using (HotAshContext context = new HotAshContext()) {
                Cigar addCigar = context.Cigars.FirstOrDefault(x => x.ID == id);

                if (addCigar != null)
                {
                    var sameItemInCart = context.ShoppingCarts.FirstOrDefault(x => x.Cigar.ID == id && x.UserID == UserID);
                    if (sameItemInCart == null)
                    {
                        ShoppingCart sc = new ShoppingCart {
                            Cigar     = addCigar,
                            UserID    = UserID,
                            Quantity  = 1,
                            DateAdded = DateTime.Now
                        };
                        context.ShoppingCarts.Add(sc);
                    }
                    else
                    {
                        sameItemInCart.Quantity++;
                    }

                    context.SaveChanges();
                }
                ShoppingCartSummary summary = GetShoppingCartSummary(context);
                return(PartialView("_AjaxCartSummary", summary));
            }
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("BrandId,CigarName,StrenghtId,TasteId,SizeId,QuestionId,Bland,DescriptionId,ShapeId,PricePerUnit,ImageUrl,IsDeleted,DeletedOn,Id,CreatedOn,ModifiedOn")] Cigar cigar)
        {
            if (id != cigar.Id)
            {
                return(this.NotFound());
            }

            if (this.ModelState.IsValid)
            {
                try
                {
                    this.cigarEntity.Update(cigar);
                    await this.cigarEntity.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!this.CigarExists(cigar.Id))
                    {
                        return(this.NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(this.RedirectToAction(nameof(this.Index)));
            }

            return(this.View(cigar));
        }
Exemplo n.º 7
0
        public IActionResult DeleteCigar(int id)
        {
            Cigar ciggy = _cigarData.Delete(id, _context.Cigars);

            _context.Cigars.Remove(ciggy);
            _context.SaveChanges();
            return(Ok("Item removed!"));
        }
Exemplo n.º 8
0
        public async void DeleteShouldInvokeRemoveCigarAndReturnNoContentResult()
        {
            var expected = new Cigar();

            var actionResult = await controller.Delete(expected.Id);

            mockCigarService.Verify(x => x.RemoveCigar(expected.Id));
            actionResult.Should().BeOfType <NoContentResult>();
        }
Exemplo n.º 9
0
        public async Task <ActionResult <Cigar> > PostCigar(Cigar cigar)
        {
            // Indicate to the database context we want to add this new record
            _context.Cigars.Add(cigar);
            await _context.SaveChangesAsync();

            // Return a response that indicates the object was created (status code `201`) and some additional
            // headers with details of the newly created object.
            return(CreatedAtAction("GetCigar", new { id = cigar.Id }, cigar));
        }
Exemplo n.º 10
0
        public ActionResult Edit(int id, Cigar obj)
        {
            using (HotAshContext context = new HotAshContext()) {
                var cigar = context.Cigars.FirstOrDefault(x => x.ID == id);
                TryUpdateModel(cigar);
                context.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 11
0
        public void ShouldBindStateToProperties()
        {
            CigarState state = new CigarState()
            {
                Id = Guid.NewGuid()
            };

            Cigar cigar = Cigar.Load(state);

            Assert.Equal(state.Id, cigar.Id);
        }
Exemplo n.º 12
0
        public Cigar Delete(int id, IEnumerable <Cigar> cigarList)
        {
            List <Cigar> ListofCigars = cigarList.ToList();
            Cigar        cigar        = ListofCigars.FirstOrDefault(c => c.Id == id);

            if (cigar != null)
            {
                ListofCigars.Remove(cigar);
            }
            return(cigar);
        }
Exemplo n.º 13
0
        public async Task ShouldSaveProvidedCigar()
        {
            SqlCigarRepository repository = CreateRepository();

            Cigar newCigar = Cigar.New();

            await repository.Save(newCigar);

            Cigar savedCigar = await repository.Load(newCigar.Id);

            Assert.Equal(newCigar.Id, savedCigar.Id);
        }
Exemplo n.º 14
0
        public async void UpdateShouldInvokeEditCigarWithParameterItemWhenItemExists()
        {
            var expected = new Cigar {
                Id = 1
            };

            mockCigarService.Setup(x => x.CigarExists(It.IsAny <int>())).ReturnsAsync(true);

            await controller.Update(expected.Id.ToString(), expected);

            mockCigarService.Verify(x => x.EditCigar(expected));
        }
Exemplo n.º 15
0
 public ActionResult Create(Cigar obj)
 {
     try {
         using (HotAshContext context = new HotAshContext()) {
             context.Cigars.Add(obj);
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
     } catch {
         return(View());
     }
 }
Exemplo n.º 16
0
        public Cigar Update(Cigar updatedCigar)
        {
            var cigar = cigars.SingleOrDefault(c => c.Id == updatedCigar.Id);

            if (cigar != null)
            {
                cigar.Name        = updatedCigar.Name;
                cigar.Type        = updatedCigar.Type;
                cigar.Description = updatedCigar.Description;
            }
            return(cigar);
        }
Exemplo n.º 17
0
        /// <inheritdoc />
        public async Task <Guid> Handle(AddCigarCommand request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            Cigar cigar = Cigar.New();

            await _cigarRepository.Save(cigar);

            return(cigar.Id);
        }
Exemplo n.º 18
0
        public async void UpdateShouldInvokeEditCigarAndReturnNoContentResult()
        {
            var expected = new Cigar {
                Id = 1
            };

            mockCigarService.Setup(x => x.CigarExists(It.IsAny <int>())).ReturnsAsync(true);

            var actionResult = await controller.Update("1", expected);

            mockCigarService.Verify(x => x.EditCigar(expected));
            actionResult.Should().BeOfType <NoContentResult>();
        }
Exemplo n.º 19
0
        public Cigar Add(Cigar newCigar, IEnumerable <Cigar> cigarList)
        {
            List <Cigar> ListofCigars = cigarList.ToList();
            Cigar        duplicated   = null;

            duplicated = ListofCigars.Find(c => c.Name == newCigar.Name);
            if (duplicated == null)
            {
                ListofCigars.Add(newCigar);
                newCigar.Id = ListofCigars.Max(c => c.Id) + 1;
            }
            return(newCigar);
        }
Exemplo n.º 20
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            try {
                using (HotAshContext context = new HotAshContext()) {
                    Cigar cigar = context.Cigars.FirstOrDefault(x => x.ID == id);
                    context.Cigars.Remove(cigar);
                    context.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            } catch {
                return(View());
            }
        }
Exemplo n.º 21
0
        // GET: CigarAdmin/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }

            Cigar result = null;

            using (HotAshContext context = new HotAshContext()) {
                result = context.Cigars.FirstOrDefault(x => x.ID == id);
            }
            return(View(result));
        }
Exemplo n.º 22
0
        public IActionResult PostCigar(Cigar cigar)
        {
            Cigar ciggy = _cigarData.Add(cigar, _context.Cigars);

            if (ciggy.Id == 0)
            {
                return(Ok("Already exists!"));
            }
            else
            {
                _context.Add(ciggy);
                _context.SaveChanges();
                return(Ok("Item added!"));
            }
        }
Exemplo n.º 23
0
        public async void GetByIdShouldReturnCigarWithWantedId()
        {
            var expected = new Cigar()
            {
                Id = 1
            };

            mockCigarService.Setup(x => x.GetCigarById(expected.Id)).ReturnsAsync(expected);

            var actionResult = await controller.Get(1);

            actionResult.Should().BeOfType <ObjectResult>()
            .Which.Value.Should().BeAssignableTo <Cigar>()
            .Which.Should().Be(expected);
        }
Exemplo n.º 24
0
 public int SaveCigar(Cigar cigar)
 {
     lock (locker)
     {
         if (cigar.Id != 0)
         {
             database.Update(cigar);
             return(cigar.Id);
         }
         else
         {
             return(database.Insert(cigar));
         }
     }
 }
Exemplo n.º 25
0
        public async Task <IActionResult> Create([FromBody] Cigar item)
        {
            if (item == null)
            {
                return(BadRequest(ModelState));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await cigarService.AddNewCigar(item);

            return(CreatedAtRoute("GetCigar", new { id = result }, item));
        }
Exemplo n.º 26
0
        public bool CreateCigar(CigarCreate model)
        {
            var entity =
                new Cigar
            {
                CigarName   = model.CigarName,
                MakerId     = model.MakerId,
                CigarTypeId = model.CigarTypeId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Cigars.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 27
0
        // GET: Cigars/Details/5
        public ActionResult Details(int?id)
        {
            if (User.IsInRole("Admin"))
            {
                return(RedirectToAction("Index", "CigarAdmin"));
            }

            if (id == null)
            {
                return(RedirectToAction("Index"));
            }

            using (HotAshContext context = new HotAshContext()) {
                Cigar cigar = context.Cigars.FirstOrDefault(x => x.ID == id);
                return(View(cigar));
            }
        }
Exemplo n.º 28
0
        public async Task CreateCigar(CreateCigarInputModel input)
        {
            var cigar = new Cigar
            {
                BrandId      = input.BrandId,
                CigarName    = input.CigarName,
                StrenghtId   = input.StrenghtId,
                TasteId      = input.TasteId,
                SizeId       = input.SizeId,
                Bland        = input.Bland,
                ShapeId      = input.ShapeId,
                PricePerUnit = input.PricePerUnit,
                ImageUrl     = input.ImageUrl,
            };

            await this.cigarRepository.AddAsync(cigar);

            await this.cigarRepository.SaveChangesAsync();
        }
Exemplo n.º 29
0
        public async Task <IActionResult> Update(string id, [FromBody] Cigar item)
        {
            if (item == null || item.Id != int.Parse(id))
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!await cigarService.CigarExists(item.Id))
            {
                return(NotFound());
            }

            await cigarService.EditCigar(item);

            return(NoContent());
        }
Exemplo n.º 30
0
        /// <inheritdoc />
        public Task Save(Cigar cigar)
        {
            if (cigar == null)
            {
                throw new ArgumentNullException(nameof(cigar));
            }

            string data = _serializer.Serialize(cigar);

            var parameters = new
            {
                cigar.Id,
                Data = data
            };

            return(_client.ExecuteInManagedConnectionAsync(connection =>
                                                           connection.ExecuteAsync(
                                                               "[Catalog].[Cigars_Save]",
                                                               parameters,
                                                               commandType: CommandType.StoredProcedure)
                                                           ));
        }