示例#1
0
        public async Task <IActionResult> PutAnimal(int id, Animal animal)
        {
            if (id != animal.Id)
            {
                return(BadRequest());
            }

            _context.Entry(animal).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AnimalExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#2
0
        public async Task <IActionResult> PutCatchServiceEmployee(int id, CatchServiceEmployee catchServiceEmployee)
        {
            if (id != catchServiceEmployee.Id)
            {
                return(BadRequest());
            }

            _context.Entry(catchServiceEmployee).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CatchServiceEmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#3
0
        public async Task <IActionResult> PutShelter(int id, Shelter shelter)
        {
            if (id != shelter.Id)
            {
                return(BadRequest());
            }

            _context.Entry(shelter).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ShelterExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("DonationID,DateOfDonation,UsersFK")] DonationIndexViewModel donationIVM)
        {
            if (!GetAuthorization(5, 'c'))
            {
                return(NotFound());
            }
            ViewBag.Permission = getPermissions();
            if (!checkValues(donationIVM))
            {
                return(Redirect(nameof(Create)));
            }

            if (ModelState.IsValid)
            {
                string   selected     = Request.Form["checkProduct"].ToString();
                string[] selectedList = selected.Split(',');
                Donation donation     = new Donation
                {
                    DateOfDonation = donationIVM.DateOfDonation,
                    UsersFK        = donationIVM.UsersFK
                };
                _context.Add(donation);
                _context.SaveChanges();

                if (selectedList[0] != "")
                {
                    foreach (var temp in selectedList)
                    {
                        int prodKey  = Convert.ToInt32(temp);
                        int newQuant = 0;
                        if (Request.Form["quantityProduct " + Convert.ToInt32(temp)] != "")
                        {
                            newQuant = Convert.ToInt32(Request.Form["quantityProduct " + Convert.ToInt32(temp)].ToString());
                        }
                        DonationProduct donationProduct = new DonationProduct
                        {
                            DonationFK = donation.DonationID,
                            ProductFK  = prodKey,
                            Quantity   = newQuant
                        };
                        var prod = new Product
                        {
                            ProductID = prodKey
                        };
                        prod.Quantity = _context.Products.Where(e => e.ProductID == prodKey).FirstOrDefault().Quantity + newQuant;
                        _context.Entry(prod).Property("Quantity").IsModified = true;
                        _context.SaveChanges();
                        _context.Add(donationProduct);
                    }
                }

                await _context.SaveChangesAsync();

                TempData["Message"] = "Doacao criada com sucesso!";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(donationIVM));
        }
        public async Task <IActionResult> Create([Bind("appointmentID,date,animalID,ownerID")] Appointment appointment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(appointment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["animalID"] = new SelectList(_context.Animals, "animalID", "animalID", appointment.animalID);
            ViewData["ownerID"]  = new SelectList(_context.Owners, "ownerID", "ownerID", appointment.ownerID);
            return(View(appointment));
        }
        public async Task <IActionResult> Create([Bind("animalID,animalName,species,age,gender")] Animal animal)
        {
            if (animal.ValidateEntry(animal.animalName, animal.species, animal.age, animal.gender))
            {
                if (ModelState.IsValid)
                {
                    _context.Add(animal);
                    await _context.SaveChangesAsync();

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

            return(View("Fail"));
        }
示例#7
0
        public async Task <IActionResult> Create([Bind("ownerID,firstname,lastname,phonenumber")] Owner owner)
        {
            if (owner.ValidateEntry(owner.firstname, owner.lastname, owner.phonenumber))
            {
                if (ModelState.IsValid)
                {
                    _context.Add(owner);
                    await _context.SaveChangesAsync();

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

            return(View("Fail"));
        }
        public async Task <IActionResult> Create([Bind("ProductTypeID,Name")] ProductType productType)
        {
            if (!GetAuthorization(3, 'c'))
            {
                return(NotFound());
            }
            ViewBag.Permission = getPermissions();
            if (!checkValues(productType))
            {
                return(View(productType));
            }
            if (ModelState.IsValid)
            {
                _context.Add(productType);
                await _context.SaveChangesAsync();

                TempData["Message"] = "Tipo de produto criado com sucesso!";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(productType));
        }
        public async Task <IActionResult> Create([Bind("AnimalRaceID,Name")] AnimalRace animalRace)
        {
            if (!GetAuthorization(7, 'c'))
            {
                return(NotFound());
            }
            ViewBag.Permission = getPermissions();
            if (!checkValues(animalRace))
            {
                return(View(animalRace));
            }
            if (ModelState.IsValid)
            {
                _context.Add(animalRace);
                await _context.SaveChangesAsync();

                TempData["Message"] = "Raça de animal criado com sucesso!";
                return(RedirectToAction(nameof(Index)));
            }
            return(View(animalRace));
        }
示例#10
0
        public async Task <IActionResult> Create([Bind("ProductID,Name,Quantity,WeekStock,MonthStock,AnimalTypeFK,ProductTypeFK")] Product product)
        {
            if (!GetAuthorization(4, 'c'))
            {
                return(NotFound());
            }
            ViewBag.Permission = getPermissions();
            if (!checkValues(product))
            {
                setViewBags();
                return(View(product));
            }
            if (ModelState.IsValid)
            {
                product.AnimalTypeFK  = Int32.Parse(Request.Form["AnimalTypeFK"].ToString());
                product.ProductTypeFK = Int32.Parse(Request.Form["ProductTypeFK"].ToString());
                _context.Add(product);
                await _context.SaveChangesAsync();

                TempData["Message"] = "Produto criado com sucesso!";
                return(RedirectToAction(nameof(Index)));
            }
            return(RedirectToAction(nameof(Index)));
        }
示例#11
0
        public async Task <IActionResult> Create([Bind("UserID,Email,Name,Password,ConfirmedEmail,Street,PostalCode,City,Phone,DateOfBirth,RoleID")] Users users)
        {
            if (!GetAuthorization(1, 'c'))
            {
                return(NotFound());
            }
            ViewBag.Permission = getPermissions();
            if (!checkValues(users))
            {
                ViewBag.RoleTypes = _context.Roles.AsParallel();
                return(View(users));
            }
            if (ModelState.IsValid)
            {
                _context.Add(users);
                await _context.SaveChangesAsync();

                /** Send Confirmation Email **/
                int user_id = (from user in _context.Users select user.UserID).Max();
                var result  = new MailSenderController(_configuration).PostMessage(users.Email, users.Name, users.UserID);

                /** End of Confirmation Email **/
                // Register User as a Customer on Stripe
                StripeLib stripeLib = new StripeLib();
                users.CustomerId = await stripeLib.CreateCustomer(users);

                await _context.SaveChangesAsync();

                insertToRegisterTable();
                TempData["Message"] = "Utilizador criado com sucesso!Por favor, o utilizador que verifique o seu email e clique no link para concluir o registo da sua conta e para prosseguir para o login!";
                return(RedirectToAction(nameof(Index)));
            }
            TempData["Message"] = "Por favor, siga os exemplos para continuar!";
            ViewBag.RoleTypes   = _context.Roles.AsParallel();
            return(View());
        }
示例#12
0
        public async Task <IActionResult> Create([Bind("RoleID,RoleName")] Roles roles)
        {
            System.Diagnostics.Debug.WriteLine("******************************************************");
            System.Diagnostics.Debug.WriteLine("Entrou");
            System.Diagnostics.Debug.WriteLine("******************************************************");
            if (!GetAuthorization(2, 'c'))
            {
                return(NotFound());
            }
            ViewBag.Permission = getPermissions();
            if (!checkValues(roles))
            {
                setViewBags(-1);
                return(View(roles));
            }
            if (ModelState.IsValid)
            {
                _context.Add(roles);
                _context.SaveChanges();
                var componenets = _context.Components.ToList();
                foreach (var comp in componenets)
                {
                    string   selectedOptions     = Request.Form[comp.Name].ToString();
                    string[] selectedOptionsList = selectedOptions.Split(',');

                    RoleAuthorization rAutho = new RoleAuthorization
                    {
                        ComponentFK = comp.ComponentID,
                        RoleFK      = roles.RoleID,
                        Create      = false,
                        Read        = false,
                        Update      = false,
                        Delete      = false
                    };

                    if (selectedOptionsList[0] != "")
                    {
                        foreach (var val in selectedOptionsList)
                        {
                            int id = Int32.Parse(val);
                            switch (id)
                            {
                            case 1:
                                rAutho.Create = true;
                                break;

                            case 2:
                                rAutho.Read = true;
                                break;

                            case 3:
                                rAutho.Update = true;
                                break;

                            case 4:
                                rAutho.Delete = true;
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    if (rAutho.Delete || rAutho.Create || rAutho.Update)
                    {
                        rAutho.Read = true;
                    }
                    _context.Add(rAutho);
                    _context.SaveChanges();
                }
                await _context.SaveChangesAsync();

                TempData["Message"] = "Permissão criada com sucesso!";
                return(RedirectToAction(nameof(Index)));
            }
            TempData["Message"] = "Model de errado aconteceu!";
            setViewBags(-1);
            return(View(roles));
        }
示例#13
0
        public async Task <IActionResult> Create([Bind("AnimalID,Name,DateOfBirth,Disinfection,Neutered,Description,Foto,Picture,AnimalTypeFK,AnimalRaceFK,OwnerFK")] Animal animal)
        {
            if (!GetAuthorization(8, 'c'))
            {
                return(NotFound());
            }
            ViewBag.Permission = getPermissions();
            if (!checkValues(animal))
            {
                setViewBags(-1);
                return(View(animal));
            }
            if (ModelState.IsValid)
            {
                string   selectedProducts     = Request.Form["checkProduct"].ToString();
                string[] selectedProductsList = selectedProducts.Split(',');

                string   selectedGodfathers    = Request.Form["checkGodfather"].ToString();
                string[] selectedGodfatherList = selectedGodfathers.Split(',');

                Animal animalAdd = new Animal()
                {
                    Name         = animal.Name,
                    DateOfBirth  = animal.DateOfBirth,
                    Disinfection = animal.Disinfection,
                    Neutered     = animal.Neutered,
                    Description  = animal.Description,
                    AnimalTypeFK = animal.AnimalTypeFK,
                    AnimalRaceFK = animal.AnimalRaceFK,
                    OwnerFK      = animal.OwnerFK
                };
                _context.Add(animalAdd);
                _context.SaveChanges();
                if (animal.Foto != null)
                {
                    System.IO.Directory.CreateDirectory(hostingEnvironment.WebRootPath + "/images/Galeria_" + animalAdd.AnimalID);
                    var uniqueFileName = GetUniqueFileName(animal.Foto.FileName);
                    var uploads        = Path.Combine(hostingEnvironment.WebRootPath, "images/Galeria_" + animalAdd.AnimalID);
                    var filePath       = Path.Combine(uploads, uniqueFileName);

                    animal.Foto.CopyTo(new FileStream(filePath, FileMode.Create));

                    Images image = new Images()
                    {
                        AnimalFK           = animalAdd.AnimalID,
                        Name               = animal.Foto.Name,
                        Length             = animal.Foto.Length,
                        FileName           = uniqueFileName,
                        ContentType        = animal.Foto.ContentType,
                        ContentDisposition = animal.Foto.ContentDisposition
                    };
                    _context.Add(image);
                    _context.SaveChanges();
                    //to do : Save uniqueFileName  to your db table
                }

                if (selectedProductsList[0] != "")
                {
                    foreach (var temp in selectedProductsList)
                    {
                        int           prodKey = Convert.ToInt32(temp);
                        AnimalProduct aniProd = new AnimalProduct()
                        {
                            AnimalFK  = animalAdd.AnimalID,
                            ProductFK = prodKey
                        };
                        _context.Add(aniProd);
                        _context.SaveChanges();
                    }
                }

                if (selectedGodfatherList[0] != "")
                {
                    foreach (var key in selectedGodfatherList)
                    {
                        int         godkey   = Convert.ToInt32(key);
                        AnimalUsers aniUsers = new AnimalUsers()
                        {
                            AnimalFK = animalAdd.AnimalID,
                            UsersFK  = godkey
                        };
                        _context.Add(aniUsers);
                        _context.SaveChanges();
                    }
                }
                await _context.SaveChangesAsync();

                TempData["Message"] = "Animal criado com sucesso!";
                return(RedirectToAction(nameof(Index)));
            }
            setViewBags(-1);
            return(View(animal));
        }