Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,MusicType")] BALIBAR.Models.Type @type)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@type);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(@type));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("Id,DateTime,AttendeesNum,BarID")] Reservation reservation)
        {
            if (ModelState.IsValid)
            {
                // Get the connected user.
                ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User);

                reservation.Customer = user;

                // If the bar was already selected beforehand - add it here.
                if (!(bool)TempData["showBars"])
                {
                    reservation.BarID = Int32.Parse(TempData["barId"] as string);
                }

                _context.Add(reservation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(reservation));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Address,Description,MaxParticipants,InOut,Kosher,Accessible,OpeningTime,ClosingTime,MinAge,ImgUrl,Type")] Bar bar)
        {
            var type = _context.Type.Where(t => t.Name == bar.Type.Name);

            if (type.Count() != 0)
            {
                bar.Type = type.ToList()[0];
                ModelState.Remove("Type.MusicType");
                ModelState.Remove("Type.Description");
                if (ModelState.IsValid)
                {
                    if (!String.IsNullOrEmpty(bar.ImgUrl) && System.IO.File.Exists(bar.ImgUrl))
                    {
                        string copyImagePath = _env.WebRootPath + "\\content\\" + Regex.Replace(bar.Name, @"\s+", "") + ".jpg";
                        System.IO.File.Copy(bar.ImgUrl, copyImagePath, true);
                        bar.ImgUrl = "/content/" + Regex.Replace(bar.Name, @"\s+", "") + ".jpg";
                    }
                    else
                    {
                        bar.ImgUrl = "/content/NoImage.jpg";
                    }

                    _context.Add(bar);
                    await _context.SaveChangesAsync();

                    FaceBookHandler.PostMessage(bar);
                    return(RedirectToAction(nameof(Index)));
                }

                return(View(bar));
            }
            else
            {
                return(new NotFoundViewResult("NotFoundError", "Bar type wasn't found"));
            }
        }