示例#1
0
        public async Task <IActionResult> PersonSaveAsync(PersonViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("PersonForm", model));
            }

            PersonDataModel dataModel = _mapper.Map <PersonDataModel>(model);

            try
            {
                if (model.Id > 0)
                {
                    await _mainService.EditPersonAsync(dataModel);
                }
                else
                {
                    await _mainService.AddPersonAsync(dataModel);
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(nameof(model.Surname), ex.Message);

                return(View("PersonForm", model));
            }

            return(RedirectToAction("Index"));
        }
示例#2
0
 static Pet ToPet(PetDataModel petDataModel, PersonDataModel personDataModel)
 {
     return(new Pet()
     {
         name = petDataModel.name,
         type = petDataModel.type,
         ownerGender = personDataModel.gender
     });
 }
示例#3
0
        /// <summary>
        /// Main Task
        /// </summary>
        /// <returns></returns>
        // GET: Persons
        public async Task <IActionResult> Index()
        {
            var vm = new PersonDataModel();

            vm.DatesList = await _bll.Obligations.DatesList(User.UserId());

            vm.UnreadMessages = (await _bll.Persons.OnePerson(User.UserId())).UnreadMessages;
            //var applicationDbContext = await _bll.Persons.AllFamilyPersons(User.UserGuidId());
            vm.Persons = await _bll.Persons.AllFamilyPersons(User.UserId());

            return(View(vm));
        }
示例#4
0
        public void SerializationTest()
        {
            BinaryFormatter formatter = new BinaryFormatter();

            using (MemoryStream stream = new MemoryStream())
            {
                PersonDataModel person = new PersonDataModel() { Name = "Hugo" };
                formatter.Serialize(stream, person);

                stream.Position = 0;
                PersonDataModel newPerson = (PersonDataModel)formatter.Deserialize(stream);
                Assert.AreEqual(person.Name, newPerson.Name);
            }
        }
示例#5
0
        public async Task AddPersonAsync(PersonDataModel person)
        {
            Person entity = _mapper.Map <Person>(person);

            try
            {
                _context.Persons.Add(entity);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
示例#6
0
 public static int PersonUpsert(PersonDataModel personDataModel)
 {
     using (var connection = new SqlConnection(ConnectionFactory.Connection))
     {
         return((int)connection.ExecuteScalar("uspPersonUpsert",
                                              new {
             person_id = personDataModel.PersonId,
             first_name = personDataModel.FirstName,
             last_name = personDataModel.LastName,
             state_id = personDataModel.StateId,
             gender = personDataModel.Gender,
             dob = personDataModel.Dob
         }, commandType: CommandType.StoredProcedure));
     }
 }
示例#7
0
        public async Task EditPersonAsync(PersonDataModel person)
        {
            if (!(_context.Persons.Include(o => o.Contacts).AsNoTracking().FirstOrDefault(i => i.Id == person.Id) is Person entity))
            {
                throw new Exception("Контакт не найден.");
            }

            Person newEntity = _mapper.Map <Person>(person);

            try
            {
                _context.Entry(newEntity).State = EntityState.Modified;

                List <int> listToEditContactId = newEntity.Contacts.Select(i => i.Id).ToList().Intersect(entity.Contacts.Select(e => e.Id).ToList()).ToList();

                List <int> listToAddContactId = newEntity.Contacts.Select(i => i.Id).ToList().Except(entity.Contacts.Select(e => e.Id).ToList()).ToList();

                List <int> listToRemoveContactId = entity.Contacts.Select(i => i.Id).ToList().Except(newEntity.Contacts.Select(e => e.Id).ToList()).ToList();


                foreach (var contact in newEntity.Contacts.Where(i => listToEditContactId.Contains(i.Id)))
                {
                    _context.Entry(contact).State = EntityState.Modified;
                }

                foreach (var contact in entity.Contacts.Where(i => listToRemoveContactId.Contains(i.Id)))
                {
                    ContactInfo contactEntity = await _context.Contacts.FindAsync(contact.Id);

                    _context.Contacts.Remove(contactEntity);
                }

                foreach (var contact in newEntity.Contacts.Where(i => listToAddContactId.Contains(i.Id)))
                {
                    contact.PersonId = entity.Id;

                    _context.Contacts.Add(contact);
                }

                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
示例#8
0
        /// <summary>
        /// Страница создания/редактирования контакта
        /// </summary>
        /// <param name="personId"></param>
        /// <returns></returns>
        public async Task <IActionResult> PersonFormAsync(int?personId)
        {
            PersonViewModel model = new PersonViewModel();

            if (!personId.HasValue)
            {
                return(View(model));
            }

            PersonDataModel person = await _mainService.GetPersonAsync(personId.Value);

            if (person != null)
            {
                model = _mapper.Map <PersonViewModel>(person);
            }

            return(View(model));
        }
示例#9
0
 public IActionResult PersonData([FromBody] PersonDataModel data)
 {
     return(Ok());
 }
示例#10
0
        public IActionResult Index(String actionBtn, IEnumerable <int> peopleChecked, PersonDataModel prsObj)
        {
            //Read the information from the json file
            var json   = new WebClient().DownloadString("./data.json");
            var people = JsonConvert.DeserializeObject <List <PersonDataModel> >(json);

            //Check which button was clicked
            if (actionBtn == "Remove")
            {
                //Loop through the CheckedId that are going to be removed
                foreach (int CheckedId in peopleChecked)
                {
                    //Find the mathching ids that were checked off in the json data
                    var item = people.SingleOrDefault(x => x.id == CheckedId);

                    //Remove the items that were checked off
                    people.Remove(item);
                }

                //Make new json from list with items removed
                var convertedJson = JsonConvert.SerializeObject(people, Formatting.Indented);

                //Save the new json file and overwrite the old one
                using (var writer = new StreamWriter("./data.json", false))
                {
                    writer.Write(convertedJson);
                }
            }
            else
            {
                //Get the total items in the table and add one for new id
                prsObj.id = people[people.Count - 1].id + 1;
                //Add the new person to the list
                people.Add(prsObj);
                //Make new json from list with new item added
                var convertedJson = JsonConvert.SerializeObject(people, Formatting.Indented);
                //Save the new json file and overwrite the old one
                using (var writer = new StreamWriter("./data.json", false))
                {
                    writer.Write(convertedJson);
                }
            }

            //Redirect back to index so page can refresh without resending post information.
            return(RedirectToAction("Index", "Home"));
        }
示例#11
0
 public PersonDataModelDto(PersonDataModel model) : base(model)
 {
     name = model.Name;
     rg   = model.Rg;
     cpf  = model.Cpf;
 }
示例#12
0
 public IActionResult PersonData([FromBody] PersonDataModel data)
 {
     return(Ok(new { Age = 20, FirstName = data.firstname, LastName = data.lastname }));
 }
示例#13
0
 static List <Pet> ListPets(PersonDataModel personDataModel)
 {
     return((personDataModel.pets ?? new List <PetDataModel>())
            .Select(pet => ToPet(pet, personDataModel))
            .ToList());
 }