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));
        }
예제 #2
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));
        }
예제 #3
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));
        }
예제 #5
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));
        }
예제 #6
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));
        }