コード例 #1
0
        public async Task <IActionResult> Update(long id, [FromBody] Setting item)
        {
            if (item == null || id == 0)
            {
                return(BadRequest());
            }

            var setting = _context.Setting.FirstOrDefault(s => s.id == id);

            if (setting == null)
            {
                return(NotFound());
            }

            foreach (PropertyInfo prop in item.GetType().GetProperties())
            {
                if (prop.Name != "id")
                {
                    prop.SetValue(setting, prop.GetValue(item));
                }
            }

            _context.Setting.Update(setting);
            _context.SaveChanges();
            await _menuHubContext.Clients.All.SendAsync("SettingUpdated", setting);

            return(Ok(new { message = "Setting is updated successfully." }));
        }
コード例 #2
0
        public ActionResult Edit(List <int> BarId, string BeerName, string BeerBreweryName, string BeerStyle, string BeerAbv, int BeerIbu, int id)
        {
            BeerDetailsViewModel viewModel = new BeerDetailsViewModel(_db, id);

            viewModel.CurrentBeer.BeerName        = BeerName;
            viewModel.CurrentBeer.BeerBreweryName = BeerBreweryName;
            viewModel.CurrentBeer.BeerStyle       = BeerStyle;
            viewModel.CurrentBeer.BeerAbv         = Convert.ToDouble(BeerAbv);
            viewModel.CurrentBeer.BeerIbu         = BeerIbu;

            var beersToRemove = _db.Taplists.Where(entry => entry.BeerId == id).ToList();

            foreach (var beer in beersToRemove)
            {
                if (beer != null)
                {
                    _db.Taplists.Remove(beer);
                }
            }

            foreach (var barId in BarId)
            {
                Bar     bar        = _db.Bars.FirstOrDefault(item => item.BarId == barId);
                Taplist newTaplist = new Taplist(id, bar.BarId);
                _db.Taplists.Add(newTaplist);
            }

            _db.SaveChanges();
            return(RedirectToAction("Details", new { id = viewModel.CurrentBeer.BeerId }));
        }
コード例 #3
0
        public ActionResult Edit(Bar bar, List <int> BeerId, string BarName, string BarRating, string BarWebsite, string BarStreet, string BarCity, string BarState, string BarZip, string BarPhone, string BarLatitude, string BarLongitude, string BarNeighborhood, int id)
        {
            BarDetailsViewModel viewModel = new BarDetailsViewModel(_db, id);

            viewModel.CurrentBar.BarName         = BarName;
            viewModel.CurrentBar.BarRating       = int.Parse(BarRating);
            viewModel.CurrentBar.BarWebsite      = BarWebsite;
            viewModel.CurrentBar.BarStreet       = BarStreet;
            viewModel.CurrentBar.BarCity         = BarCity;
            viewModel.CurrentBar.BarState        = BarState;
            viewModel.CurrentBar.BarZip          = BarZip;
            viewModel.CurrentBar.BarPhone        = BarPhone;
            viewModel.CurrentBar.BarLatitude     = Convert.ToDouble(BarLatitude);
            viewModel.CurrentBar.BarLongitude    = Convert.ToDouble(BarLongitude);
            viewModel.CurrentBar.BarNeighborhood = BarNeighborhood;
            var barsToRemove = _db.Taplists.Where(entry => entry.BarId == id).ToList();

            foreach (var bars in barsToRemove)
            {
                if (bars != null)
                {
                    _db.Taplists.Remove(bars);
                }
            }

            foreach (int beerId in BeerId)
            {
                Taplist newTaplist = new Taplist(beerId, viewModel.CurrentBar.BarId);
                _db.Taplists.Add(newTaplist);
            }
            _db.SaveChanges();

            return(RedirectToAction("Details", new { id = viewModel.CurrentBar.BarId }));
        }
コード例 #4
0
        public async Task <IActionResult> UploadLabel(int beerId)
        {
            Beer beer = _context.Beer.Where(b => b.id == beerId).FirstOrDefault();

            using (var ms = new MemoryStream())
            {
                var file = Request.Form.Files.FirstOrDefault();
                await file.CopyToAsync(ms);

                Label label = new Label()
                {
                    image     = ms.ToArray(),
                    extension = file.FileName.Substring(file.FileName.LastIndexOf('.') + 1)
                };

                Label oldLabel = _context.Label.Where(l => l.id == beer.labelId).FirstOrDefault();
                if (oldLabel != null)
                {
                    _context.Label.Remove(oldLabel);
                }
                _context.Label.Add(label);
                _context.SaveChanges();

                beer.labelId = label.id.Value;
                _context.Beer.Update(beer);
                _context.SaveChanges();

                await _menuHubContext.Clients.All.SendAsync("LabelUpdated", label, beerId);

                return(Ok());
            }
        }
コード例 #5
0
        public IActionResult Create([FromBody] Style item)
        {
            if (item == null)
            {
                return(BadRequest());
            }
            _context.Style.Add(item);
            _context.SaveChanges();

            return(Ok(new { message = "Style added successfully." }));
        }
コード例 #6
0
        public async Task <IActionResult> AddBeer(int beerId)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            UserBeer userBeer = new UserBeer(userId.ToString(), beerId);

            userBeer.User = currentUser;
            _db.UsersBeers.Add(userBeer);
            _db.SaveChanges();
            return(View("Details"));
        }
コード例 #7
0
ファイル: TapController.cs プロジェクト: reidarma/WhatsOnTap
        public async Task <IActionResult> Create([FromBody] Tap item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            _context.Tap.Add(item);
            _context.SaveChanges();

            ReorderTapsOnAddEdit(item);
            _context.SaveChanges();

            item.beer = _context.Beer
                        .Where(b => b.id == item.beerId)
                        .Include(b => b.style)
                        .Include(b => b.label)
                        .FirstOrDefault();

            await _menuHubContext.Clients.All.SendAsync("TapCreated", item);

            return(Ok(new { message = "Tap added successfully." }));
        }