Пример #1
0
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            Log log = new Log()
            {
                LogDate = DateTime.Now, LogType = "LOGIN"
            };

            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false);

                if (result.Succeeded)
                {
                    var user = await _userManager.FindByEmailAsync(model.Email);

                    if (user.Banned)
                    {
                        log.LogValue = "BANNED";
                        _context.Add(log);
                        _context.SaveChanges();
                        await _signInManager.SignOutAsync();

                        return(Redirect("~/"));
                    }

                    log.LogValue = "SUCCESSFUL";
                    _context.Add(log);
                    _context.SaveChanges();
                    _logger.LogInformation(1, _localizer["Label_UserLogged"]);
                    NewLocation();
                    return(Redirect("~/"));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToAction(nameof(SendCode), new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    log.LogValue = "LOCKED";
                    _context.Add(log);
                    _context.SaveChanges();
                    _logger.LogWarning(2, _localizer["Error_BannedUser"]);
                    return(View("Lockout"));
                }

                else
                {
                    log.LogValue = "FAIL";
                    _context.Add(log);
                    _context.SaveChanges();
                    ModelState.AddModelError(string.Empty, _localizer["Error_InvalidLoginAt"]);
                    return(View(model));
                }
            }

            return(View(model));
        }
        public async Task <IActionResult> Create([Bind("InterventionId,Date,Completed,Details")] AnimalIntervention animalIntervention, int animalID, int userID)
        {
            animalIntervention.User   = _context.Users.Find(userID);
            animalIntervention.Animal = _context.Animals.Find(animalID);
            var owner = _context.Users.Find(animalIntervention.Animal.UserId);

            if (animalIntervention.User != null && animalIntervention.Animal != null && owner != null)
            {
                _context.Add(animalIntervention);
                await _context.SaveChangesAsync();

                _notificationService.Register(_context, new UserNotification()
                {
                    UserId           = owner.Id,
                    Title            = "Nova intervenção marcada",
                    Message          = "Foi agendada uma nova intervenção medica para o " + animalIntervention.Animal.Name + " na data " + animalIntervention.Date + " com o veterinario(a) " + animalIntervention.User.Name,
                    NotificationDate = DateTime.Now
                }, _emailSender);

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

            ViewBag.Users   = _context.Users.ToList();
            ViewBag.Animals = _context.Animals.ToList();
            return(View(animalIntervention));
        }
Пример #3
0
        public async Task <IActionResult> Create(Animal animal, [Bind(Prefix = "Animal.Image")] IFormFile image)
        {
            var speciesSet = _context.AnimalSpecies;
            var rqf        = _httpContextAccessor.HttpContext.Features.Get <IRequestCultureFeature>();
            var culture    = rqf.RequestCulture.Culture;
            var viewModel  = new AnimalViewModel(culture)
            {
                Species = speciesSet
            };

            if (ModelState.IsValid)
            {
                if (image != null)
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        await image.CopyToAsync(memoryStream);

                        memoryStream.Position = 0;
                        Account    account      = new Account("adotaqui", "763436643874459", "G8jgeFUttCwjs-y-aJ0vjzLkUOA");
                        Cloudinary cloudinary   = new Cloudinary(account);
                        Random     random       = new Random();
                        var        uploadParams = new ImageUploadParams()
                        {
                            Folder = "adotaqui",
                            File   = new FileDescription(random.Next(10000000, 99999999).ToString(), memoryStream)
                        };
                        var uploadResult = cloudinary.Upload(uploadParams);
                        animal.Image = uploadResult.SecureUri.ToString();
                    }
                }
                animal.Breed = _context.AnimalBreeds.FirstOrDefault(a => a.BreedId == animal.Breed.BreedId);
                _context.Add(animal);
                await _context.SaveChangesAsync();

                viewModel.StatusMessage = new StatusMessage {
                    Type = MessageType.Success, Value = "O animal foi criado com sucesso."
                };
                return(View(viewModel));
            }
            viewModel.StatusMessage = new StatusMessage {
                Type = MessageType.Error, Value = "Não foi possível criar o animal."
            };
            return(View(viewModel));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("CommentId,AnimalId,UserId,Commentary")] AnimalComment animalComment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(animalComment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(animalComment));
        }
Пример #5
0
        public async Task <IActionResult> Create([Bind("Email,PasswordHash,Name,Birthday,PhoneNumber,Id,UserName,NormalizedUserName,NormalizedEmail,EmailConfirmed,SecurityStamp,ConcurrencyStamp,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public async Task <IActionResult> Create([Bind("UserNotificationId,NotificationDate,HasRead,Title,Message,UserId")] UserNotification userNotification)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userNotification);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userNotification));
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("LogId,LogType,LogValue,LogDate")] Log log)
        {
            if (ModelState.IsValid)
            {
                _context.Add(log);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(log));
        }