public int AddOwner(NewOwnerVm model) { var deposit = _mapper.Map <Owner>(model); var id = _ownerRepository.AddOwner(deposit); return(id); }
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)); } }
public Owner AddOwner(Owner owner) { if (owner != null) { return(OwnerRepository.AddOwner(owner)); } return(null); }
public IActionResult AddOwner([FromBody] Owner owner) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _ownerRepository.AddOwner(owner); return(new JsonResult(owner.OwnerId)); }
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); }
public ActionResult Create(Owner owner) { try { _ownerRepo.AddOwner(owner); return(RedirectToAction("Index")); } catch (Exception ex) { return(View(owner)); } }
public ActionResult Create(Owner owner) { try { _ownerRepo.AddOwner(owner); return(RedirectToAction(nameof(Index))); } catch { return(View(owner)); } }
public ActionResult Create(OwnerFormViewModel vm) { try { _ownerRepo.AddOwner(vm.Owner); return(RedirectToAction("Details", new { id = vm.Owner.Id })); } catch { return(View(vm)); } }
public ActionResult Create(OwnerFormViewModel vm) { try { _ownerRepository.AddOwner(vm.Owner); return(RedirectToAction("Index")); } catch (Exception ex) { return(View(vm)); } }
public async Task AddOwner(OwnerInformation ownerInformation) { var log = new Log() { Name = "AddOwner", Time = DateTime.Now }; await _collection.InsertOneAsync(log); await _repository.AddOwner(ownerInformation); }
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)); } }
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)); } }
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)); }
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)); } }
public ActionResult Create(OwnerFormViewModel vm) { try { _ownerRepository.AddOwner(vm.Owner); return(RedirectToAction(nameof(Index))); } catch { return(View(vm)); } }
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)); } }
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)); } }
public ActionResult Create(OwnerFormViewModel vm) { Owner owner = vm.Owner; try { _ownerRepo.AddOwner(owner); return(RedirectToAction("Index")); } catch (Exception ex) { return(View(owner)); } }
public ActionResult Create(Owner owner) { OwnerFormViewModel vm = CreateFormViewModel(new Owner()); try { _ownerRepo.AddOwner(owner); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { return(View(vm)); } }
public ActionResult Create(Owner owner) { try { //owner.NeighborhoodId = 1; _ownerRepo.AddOwner(owner); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { return(View(owner)); } }
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)); }
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)); } }
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)); }
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)); }
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)); } }
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)); } }
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)); }
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); }
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, "Ошибка"); } }