Beispiel #1
0
        public async Task <IActionResult> VetEdit(VetRegistrationViewModel vetRegistrationViewModel, int id)
        {
            var findVet = _context.GetVetById(id);

            if (findVet == null)
            {
                return(NotFound());
            }
            else
            {
                if (ModelState.IsValid)
                {
                    if (vetRegistrationViewModel.VetPhoto != null)
                    {
                        string folder = "Images/VetPhoto/";
                        folder += Guid.NewGuid().ToString() + "_" + vetRegistrationViewModel.VetPhoto.FileName;

                        vetRegistrationViewModel.VetImageUrl = "/" + folder;

                        string serverFolder = Path.Combine(_env.WebRootPath, folder);

                        await vetRegistrationViewModel.VetPhoto.CopyToAsync(new FileStream(serverFolder, FileMode.Create));
                    }
                    findVet.Name        = vetRegistrationViewModel.Name;
                    findVet.Surname     = vetRegistrationViewModel.Surname;
                    findVet.Age         = vetRegistrationViewModel.Age;
                    findVet.Adress      = vetRegistrationViewModel.Adress;
                    findVet.City        = vetRegistrationViewModel.City;
                    findVet.PhoneNumber = vetRegistrationViewModel.PhoneNumber;
                    findVet.Position    = vetRegistrationViewModel.Position;
                    findVet.About       = vetRegistrationViewModel.About;
                    findVet.CompanyName = vetRegistrationViewModel.CompanyName;
                    if (vetRegistrationViewModel.VetImageUrl == null)
                    {
                        vetRegistrationViewModel.VetImageUrl = findVet.VetphotoUrl;
                    }
                    else
                    {
                        findVet.VetphotoUrl = vetRegistrationViewModel.VetImageUrl;
                    }
                    _context.SaveChange();
                    return(RedirectToAction("VetDetails", "Vet", new { id = findVet.ID }));
                }
            }
            return(View());
        }
Beispiel #2
0
        public IActionResult VetEdit(int id)
        {
            var getVet = _context.GetVetById(id);
            VetRegistrationViewModel vetRegistracion = new VetRegistrationViewModel
            {
                Name        = getVet.Name,
                Surname     = getVet.Surname,
                Age         = getVet.Age,
                Adress      = getVet.Adress,
                City        = getVet.City,
                Email       = getVet.Email,
                PhoneNumber = getVet.PhoneNumber,
                Position    = getVet.Position,
                About       = getVet.About,
                CompanyName = getVet.CompanyName,
            };

            return(View(vetRegistracion));
        }
Beispiel #3
0
        public async Task <IActionResult> VetRegistration(VetRegistrationViewModel vetRegistrationViewModel)
        {
            if (ModelState.IsValid)
            {
                if (vetRegistrationViewModel.VetPhoto != null)
                {
                    string folder = "Images/VetPhoto/";
                    folder += Guid.NewGuid().ToString() + "_" + vetRegistrationViewModel.VetPhoto.FileName;

                    vetRegistrationViewModel.VetImageUrl = "/" + folder;

                    string serverFolder = Path.Combine(_env.WebRootPath, folder);

                    await vetRegistrationViewModel.VetPhoto.CopyToAsync(new FileStream(serverFolder, FileMode.Create));
                }
                var findUser = await _userManager.FindByNameAsync(User.Identity.Name);

                var vet = new VetRegistracion
                {
                    UserName             = findUser.UserName,
                    RegistrationDateTime = DateTime.Now,
                    Name        = vetRegistrationViewModel.Name,
                    Surname     = vetRegistrationViewModel.Surname,
                    Age         = vetRegistrationViewModel.Age,
                    Adress      = vetRegistrationViewModel.Adress,
                    City        = vetRegistrationViewModel.City,
                    Email       = findUser.Email,
                    PhoneNumber = vetRegistrationViewModel.PhoneNumber,
                    Position    = vetRegistrationViewModel.Position,
                    About       = vetRegistrationViewModel.About,
                    CompanyName = vetRegistrationViewModel.CompanyName,
                    VetphotoUrl = vetRegistrationViewModel.VetImageUrl
                };

                _context.RegisterVet(vet);
                _context.SaveChange();
                return(RedirectToAction("VetDetails", "Vet", new { id = vet.ID }));
            }
            return(View());
        }