Ejemplo n.º 1
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"));
            }
        }
Ejemplo n.º 2
0
 public AuthController(IAuthRepository <User> authRepository, IJwtHandler jwtHandler, FaceBookHandler faceBookHandler)
 {
     this.faceBookHandler = faceBookHandler;
     this.jwtHandler      = jwtHandler;
     this.authRepository  = authRepository;
 }