Exemplo n.º 1
0
        public int AddOwner(NewOwnerVm model)
        {
            var deposit = _mapper.Map <Owner>(model);
            var id      = _ownerRepository.AddOwner(deposit);

            return(id);
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Create(OwnerFormViewModel ownerFormModel)
        {
            try
            {
                _ownerRepo.AddOwner(ownerFormModel.Owner);

                List <Claim> claims = new List <Claim>
                {
                    new Claim(ClaimTypes.NameIdentifier, ownerFormModel.Owner.Id.ToString()),
                    new Claim(ClaimTypes.Email, ownerFormModel.Owner.Email),
                    new Claim(ClaimTypes.Role, "DogOwner"),
                };

                ClaimsIdentity claimsIdentity = new ClaimsIdentity(
                    claims, CookieAuthenticationDefaults.AuthenticationScheme);

                await HttpContext.SignInAsync(
                    CookieAuthenticationDefaults.AuthenticationScheme,
                    new ClaimsPrincipal(claimsIdentity));

                return(RedirectToAction(nameof(Details), new { id = ownerFormModel.Owner.Id }));
            }
            catch
            {
                ownerFormModel.ErrorMessage  = "Whoops! Something went wrong while saving this owner";
                ownerFormModel.Neighborhoods = _neighborhoodRepo.GetAll();

                return(View(ownerFormModel));
            }
        }
Exemplo n.º 3
0
 public Owner AddOwner(Owner owner)
 {
     if (owner != null)
     {
         return(OwnerRepository.AddOwner(owner));
     }
     return(null);
 }
Exemplo n.º 4
0
 public IActionResult AddOwner([FromBody] Owner owner)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _ownerRepository.AddOwner(owner);
     return(new JsonResult(owner.OwnerId));
 }
Exemplo n.º 5
0
 public async Task RegisterUser(RegisterVM model)
 {
     var owner = new Owner()
     {
         Login    = model.Login, Password = model.Password,
         BornDate = model.BornDate, DrivingExperience = model.DrivingExperience,
         Name     = model.Name, Surname = model.Surname
     };
     await _ownerRepository.AddOwner(owner);
 }
Exemplo n.º 6
0
 public ActionResult Create(Owner owner)
 {
     try
     {
         _ownerRepo.AddOwner(owner);
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         return(View(owner));
     }
 }
Exemplo n.º 7
0
 public ActionResult Create(Owner owner)
 {
     try
     {
         _ownerRepo.AddOwner(owner);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View(owner));
     }
 }
Exemplo n.º 8
0
 public ActionResult Create(OwnerFormViewModel vm)
 {
     try
     {
         _ownerRepo.AddOwner(vm.Owner);
         return(RedirectToAction("Details", new { id = vm.Owner.Id }));
     }
     catch
     {
         return(View(vm));
     }
 }
Exemplo n.º 9
0
 public ActionResult Create(OwnerFormViewModel vm)
 {
     try
     {
         _ownerRepository.AddOwner(vm.Owner);
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         return(View(vm));
     }
 }
Exemplo n.º 10
0
        public async Task AddOwner(OwnerInformation ownerInformation)
        {
            var log = new Log()
            {
                Name = "AddOwner",
                Time = DateTime.Now
            };

            await _collection.InsertOneAsync(log);

            await _repository.AddOwner(ownerInformation);
        }
Exemplo n.º 11
0
        public ActionResult Create(Owner owner)
        {
            try
            {
                _ownerRepo.AddOwner(owner); //Does this have access to the field _ownerRepo because of line 14?

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View(owner));
            }
        }
Exemplo n.º 12
0
        public ActionResult Create(Owner owner) // ASP.NET knows how to bind values from html forms fields to C# objects
        {
            try
            {
                _ownerRepo.AddOwner(owner);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View(owner));
            }
        }
Exemplo n.º 13
0
 public IActionResult AddOwner([FromBody] Owner owner)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (string.IsNullOrEmpty(owner.Name) || string.IsNullOrEmpty(owner.Surname))
     {
         throw new Exception("Name and Surname can't be empty");
     }
     _ownerRepository.AddOwner(owner);
     return(new JsonResult(owner));
 }
Exemplo n.º 14
0
        public ActionResult Create(Owner owner)   //Method overloading, two identical methods with different parameters
        {
            try
            {
                _ownerRepo.AddOwner(owner);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View(owner));
            }
        }
Exemplo n.º 15
0
        public ActionResult Create(OwnerFormViewModel vm)
        {
            try
            {
                _ownerRepository.AddOwner(vm.Owner);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View(vm));
            }
        }
Exemplo n.º 16
0
 public ActionResult Create(OwnerFormViewModel viewModel)
 {
     try
     {
         _ownerRepo.AddOwner(viewModel.Owner);
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         viewModel.ErrorMessage = "Something went wrong";
         viewModel.Neighborhood = _neighborhoodRepo.GetAll();
         return(View(viewModel));
     }
 }
Exemplo n.º 17
0
 public ActionResult Create(OwnerFormViewModel viewModel)
 {
     try
     {
         viewModel.ErrorMessage = "Woops! Something went wrong while saving this owner";
         _ownerRepo.AddOwner(viewModel.Owner);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         viewModel.Neighborhoods = _neighborhoodRepo.GetAll();
         return(View(viewModel));
     }
 }
Exemplo n.º 18
0
        public ActionResult Create(OwnerFormViewModel vm)
        {
            Owner owner = vm.Owner;

            try
            {
                _ownerRepo.AddOwner(owner);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View(owner));
            }
        }
Exemplo n.º 19
0
        public ActionResult Create(Owner owner)
        {
            OwnerFormViewModel vm = CreateFormViewModel(new Owner());

            try
            {
                _ownerRepo.AddOwner(owner);
                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                return(View(vm));
            }
        }
Exemplo n.º 20
0
        public ActionResult Create(Owner owner)
        {
            try
            {
                //owner.NeighborhoodId = 1;
                _ownerRepo.AddOwner(owner);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                return(View(owner));
            }
        }
Exemplo n.º 21
0
        public ActionResult Create(Owner owner)
        {
            try
            {
                _ownerRepo.AddOwner(owner);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(View(owner));
            }
        }
        public ActionResult <IEnumerable <OwnerDto> > CreateOwnerCollection(IEnumerable <OwnerForCreationDto> ownerCollection)
        {
            var ownerEntities = _mapper.Map <IEnumerable <Owner> >(ownerCollection);

            foreach (var owner in ownerEntities)
            {
                _ownerRepository.AddOwner(owner);
            }

            var ownerCollectionToReturn = _mapper.Map <IEnumerable <OwnerDto> >(ownerEntities);
            var idsAsString             = string.Join(",", ownerCollectionToReturn.Select(o => o.Id));

            return(CreatedAtRoute("GetOwnerCollection", new { ids = idsAsString }, ownerCollectionToReturn));
        }
Exemplo n.º 23
0
        public ActionResult Create(OwnerFormViewModel vm)
        {
            try
            {
                _ownerRepo.AddOwner(vm.Owner);
                return(RedirectToAction("Details", new { id = vm.Owner.Id }));
            }
            catch (Exception ex)
            {
                //vm.ErrorMessage = "Woops! Something went wrong while saving this owner";
                vm.Neighborhoods = _neighborhoodRepo.GetAll();

                return(View(vm));
            }
        }
Exemplo n.º 24
0
        public ActionResult <OwnerDto> CreateOwner(OwnerForCreationDto owner)
        {
            if (owner == null)
            {
                return(BadRequest());
            }

            var ownerEntity = _mapper.Map <Owner>(owner);

            _ownerRepository.AddOwner(ownerEntity);

            var ownerToReturn = _mapper.Map <OwnerDto>(ownerEntity);

            return(CreatedAtRoute("GetOwner", new { ownerId = ownerToReturn.Id }, ownerToReturn));
        }
Exemplo n.º 25
0
        public Owner CreateOwner(Owner owner)
        {
            if (owner.OwnedPet == null || owner.OwnedPet.Id <= 0)
            {
                throw new InvalidDataException("To create an Owner you need a Pet");
            }

            if (_petshoprepository.FindPetById(owner.OwnedPet.Id) == null)
            {
                throw new InvalidDataException("Pet not found");
            }

            if (owner.Name == null)
            {
                throw new InvalidDataException("Owner needs a name");
            }
            return(_ownerRepository.AddOwner(owner));
        }
Exemplo n.º 26
0
 public ActionResult Create(OwnerFormViewModel viewModel)
 {
     //redirect user back to the index if the owner is added, passing in the viewModel for owner
     //otherwise it will stay on the create view and an error message will show
     try
     {
         _ownerRepo.AddOwner(viewModel.Owner);
         return(RedirectToAction("Index"));
     }
     catch (Exception)
     {
         //error message if an exception is thrown
         viewModel.ErrorMessage = "Woop! Something wnet wrong while saving this owner";
         //getting the list of neighborhoods again
         viewModel.Neighborhoods = _neighborhoodRepo.GetAll();
         //retruning the viewModel for owner
         return(View(viewModel));
     }
 }
Exemplo n.º 27
0
        public ActionResult Create(Owner owner)
        {
            try
            {
                _ownerRepo.AddOwner(owner);

                return(RedirectToAction("Index"));
            }
            catch (Exception)
            {
                OwnerFormViewModel vm = new OwnerFormViewModel()
                {
                    Owner         = owner,
                    Neighborhoods = _neighborhoodRepo.GetAll()
                };

                return(View(vm));
            }
        }
Exemplo n.º 28
0
 public ActionResult CreateOwner(OwnerViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(HttpNotFound());
     }
     try
     {
         Owner o = new Owner();
         ownerRepo.AddOwner(o);
         MapToOwner(o, model);
         ownerRepo.SaveChanges();
         TempData["message"] = String.Format("The owner {0} has been created", o.LastName + o.FirstName);
         return(RedirectToAction("Index"));
     }catch (Exception ex)
     {
         TempData["error"] = "There was a problem creating the owner. Please contact the IT department.";
     }
     return(View("CreateOwner", model));
 }
Exemplo n.º 29
0
        public Owner AddOwner(Owner owner)
        {
            Owner addedOwner;

            if (owner.Equals(null))
            {
                throw new InvalidDataException("Owner cannot be null");
            }

            if (owner.Name.Length < 1)
            {
                throw new InvalidDataException("Owner name has to be longer than one");
            }

            addedOwner = _ownerRepository.AddOwner(owner);
            if (addedOwner == null)
            {
                throw new DataBaseException("Something went wrong in the database");
            }

            return(addedOwner);
        }
Exemplo n.º 30
0
        private void ButtonAddOwner_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(_newOwner.Error))
                {
                    return;
                }

                int _idCounter = 1;
                foreach (Owner owner in ownerRepository.GetAll())
                {
                    _idCounter++;
                }

                _newOwner.OwnerID = _idCounter++;
                if (ownerName != null)
                {
                    _newOwner.OwnerName = ownerName;
                }
                else
                {
                    _newOwner.OwnerName = TextBoxAddOwnerName.Text;
                }

                _newOwner.OwnerAdress = TextBoxAddOwnerAdress.Text;
                _newOwner.OwnerUNP    = Int32.Parse(TextBoxAddOwnerUNP.Text);
                _newOwner.OwnerPhone  = TextBoxAddOwnerPhone.Text;

                ownerRepository.AddOwner(_newOwner);
                MessageBox.Show("Данные добавлены.");
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка");
            }
        }