Esempio n. 1
0
        public IActionResult Update(UpdatePersonViewModel model)
        {
            if (ModelState.IsValid)
            {
                Person person = new Person
                {
                    Id        = model.Id,
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Email     = model.Email,
                    Address   = model.Address
                };

                if (model?.Image?.Length > 0)
                {
                    using (var ms = new MemoryStream())
                    {
                        model.Image.CopyTo(ms);
                        var fileBytes = ms.ToArray();
                        person.Image = Convert.ToBase64String(fileBytes);
                    }
                }
                Person result = peopleService.UpdatePerson(person);
                if (result != null)
                {
                    return(RedirectToAction("Index"));
                }
            }
            return(View(model));
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="lineToUpdate">Line to update.</param>
        public UpdatePersonWindow(Line lineToUpdate)
        {
            // Instanciate the view model and set it as the data context.
            ViewModel        = new UpdatePersonViewModel(lineToUpdate);
            this.DataContext = ViewModel;

            InitializeComponent();
        }
Esempio n. 3
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] UpdatePersonViewModel person)
        {
            var updatedPerson = _mapper.Map <PersonModel>(person);

            updatedPerson.Id = id;
            await _personService.UpdatePersonAsync(updatedPerson);

            return(NoContent());
        }
Esempio n. 4
0
        public IActionResult Edit(int id)
        {
            var cities = _cityService.GetCities();
            var person = _personService.GetPersonById(id);

            var personViewModel = new UpdatePersonViewModel
            {
                Person = person,
                Cities = cities
            };

            return(View(personViewModel));
        }
Esempio n. 5
0
        public IActionResult GetPerson(GetPersonViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { error = "Не указан идентификатор записи" }));
            }

            Person person = this.dataManager.GetPerson(model.Id);

            if (person == null)
            {
                return(Json(new { error = "Контакт не найден" }));
            }

            UpdatePersonViewModel viewModel = new UpdatePersonViewModel(person);

            return(Json(new { obj = viewModel }));
        }
Esempio n. 6
0
        public IActionResult Update(int id)
        {
            var person = peopleService.GetPersonWithChilds(id);

            if (person != null)
            {
                UpdatePersonViewModel model = new UpdatePersonViewModel()
                {
                    Id           = person.Id,
                    FirstName    = person.FirstName,
                    LastName     = person.LastName,
                    Email        = person.Email,
                    Address      = person.Address,
                    CurrentImage = person.Image
                };
                return(View(model));
            }
            return(NotFound());
        }
Esempio n. 7
0
        public async Task <IActionResult> UpdatePerson([FromForm] UpdatePersonViewModel personModel)
        {
            if (personModel == null)
            {
                return(BadRequest("Object of type person is null"));
            }
            if (ModelState.IsValid)
            {
                try
                {
                    var updatedPerson = UpdatePersonToPersonDTOMapper.Instance.Map(personModel);
                    var result        = await personService.UpdatePerson(updatedPerson);

                    if (result == null)
                    {
                        logger.LogError($"Person with id {personModel.Id} not find");
                        return(NotFound());
                    }
                    else if (result.Succeeded)
                    {
                        return(RedirectToAction(nameof(GetPersonCardCabinet)));
                    }

                    else
                    {
                        AddModelErrors(result);
                    }
                }
                catch (DbUpdateException ex)
                {
                    logger.LogError($"Unable to update person becuase of {ex.Message}");
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                    return(View(personModel));
                }
            }
            return(View(personModel));
        }
Esempio n. 8
0
        public async Task <IActionResult> UpdatePersonAsync([FromBody] UpdatePersonViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { error = "На форме есть некорректные данные" }));
            }

            Organization organization = this.dataManager.FindOrganizationByName(model.OrganizationName);

            if (organization == null)
            {
                organization = new Organization {
                    Name = model.OrganizationName
                };
                await this.dataManager.AddOrganizationAsync(organization);
            }

            Position position = this.dataManager.FindPositionByName(model.PositionName);

            if (position == null)
            {
                position = new Position {
                    Name = model.PositionName
                };
                await this.dataManager.AddPositionAsync(position);
            }

            bool result = await this.dataManager.UpdatePersonAsync(model.GetDomain(organization.Id, position.Id));

            if (result)
            {
                return(Ok(new { redirectUrl = Url.Action("Index") }));
            }
            else
            {
                return(Json(new { error = "Не удалось обновить контакт" }));
            }
        }
        public async Task <IActionResult> UpdatePerson([FromBody] UpdatePersonViewModel person_model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (person_model._id_person < 1)
            {
                return(BadRequest());
            }

            var person = await _context.People.FirstOrDefaultAsync(k => k._id_person == person_model._id_person);

            if (person == null)
            {
                return(NotFound());
            }
            person.kind_of_person   = person_model.kind_of_person;
            person.name             = person_model.name;
            person.kind_of_document = person_model.kind_of_document;
            person.document_number  = person_model.document_number;
            person.telephone        = person_model.telephone;
            person.adress           = person_model.adress;
            person.email            = person_model.email;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Esempio n. 10
0
 private bool ValidateModel(UpdatePersonViewModel viewModel, out List <ValidationResult> validationErrors)
 {
     validationErrors = new List <ValidationResult>();
     return(Validator.TryValidateObject(viewModel, new ValidationContext(viewModel), validationErrors, true) &
            Validator.TryValidateObject(viewModel.Password, new ValidationContext(viewModel.Password), validationErrors, true));
 }
 public void UpdatePerson(UpdatePersonViewModel updatePersonViewModel)
 {
     _personService.UpdatePerson(updatePersonViewModel);
 }
        public void UpdatePerson(UpdatePersonViewModel updatePersonViewModel)
        {
            Person person = Mapper.Map <UpdatePersonViewModel, Person>(updatePersonViewModel);

            _personRepository.Update(person);
        }