public async Task <IActionResult> Edit(int id, [Bind("ID,Number,PersonID")] PhoneNumber phoneNumber)
        {
            if (id != phoneNumber.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(phoneNumber);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PhoneNumberExists(phoneNumber.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PersonID"] = new SelectList(_context.People, "ID", "FirstName", phoneNumber.PersonID);
            return(View(phoneNumber));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nombre,Apellido,Estado,Carrera")] Persona persona)
        {
            if (id != persona.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(persona);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersonaExists(persona.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(persona));
        }
예제 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("CityId,CityName,ZipCode,CountryRegion")] City city)
        {
            if (id != city.CityId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(city);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CityExists(city.CityId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(city));
        }
예제 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,PersonID,Address")] EMailAddress eMailAddress)
        {
            if (id != eMailAddress.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(eMailAddress);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EMailAddressExists(eMailAddress.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PersonID"] = new SelectList(_context.People, "ID", "ID", eMailAddress.PersonID);
            return(View(eMailAddress));
        }
예제 #5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,Birthday,City,State")] Person person, [Bind("PersonId,Name,DateOfAccomplishment")] Accomplishment accomplishment)
        {
            if (id != person.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (accomplishment != null)
                    {
                        person.SetOfAccomplishments.Add(accomplishment);
                    }
                    _context.Update(person);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersonExists(person.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        _log.LogWarning("The person does not exist, ID {id}", id);
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
예제 #6
0
        public async Task <IActionResult> Edit(int id, [Bind("PersonId,firstName,lastName,birthDate,age")] Person person)
        {
            if (id != person.PersonId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(person);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersonExists(person.PersonId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("PersonDetails"));
            }
            return(View(person));
        }
예제 #7
0
        public async Task <IActionResult> Edit(int id, [Bind("PersonId,Name,CPF,Birthday,Age")] Person person)
        {
            if (id != person.PersonId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(person);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersonExists(person.PersonId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
예제 #8
0
        public async Task <IActionResult> Edit(int id, [Bind("AddressId,StreetAddress,AddressType,CityId")] Address address)
        {
            if (id != address.AddressId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(address);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AddressExists(address.AddressId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CityId"] = new SelectList(_context.City, "CityId", "CityName", address.CityId);
            return(View(address));
        }
예제 #9
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,YoB")] Human human)
        {
            if (id != human.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(human);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HumanExists(human.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(human));
        }
예제 #10
0
        public async Task <IActionResult> Edit(int id, [Bind("EmailId,EmailAddress")] Email email)
        {
            if (id != email.EmailId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(email);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmailExists(email.EmailId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(email));
        }
예제 #11
0
 public void UpdatePerson(int id)
 {
     var person = _context.People.SingleOrDefault(eachPerson => eachPerson.PersonId == id);
     person.FirstName = "Hoang 123";
     _context.Update(person);
     _context.SaveChanges();
 }
        public async Task <IActionResult> Edit(int id, [Bind("PersonId,FullName,EmpCode,Position,OfficeLocation")] Person person)
        {
            if (id != person.PersonId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    personContext.Update(person);           //_context.Update(employee);
                    await personContext.SaveChangesAsync(); //_context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersonExists(person.PersonId)) //EmployeeExists(employee.EmployeeId)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
예제 #13
0
        // POST: PersonEntities/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> EditPerson(int id, PersonEntity personEntity)
        {
            if (id != personEntity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(personEntity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersonEntityExists(personEntity.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(personEntity));
        }
예제 #14
0
        public async Task <IActionResult> Edit(int id, [Bind("PersonId,FullName,EmailId,AddressId")] Person person)
        {
            if (id != person.PersonId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(person);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersonExists(person.PersonId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AddressId"] = new SelectList(_context.Address, "AddressId", "StreetAddress", person.AddressId);
            ViewData["EmailId"]   = new SelectList(_context.Email, "EmailId", "EmailAddress", person.EmailId);
            return(View(person));
        }
예제 #15
0
        public void UpdatePerson(int id)
        {
            var person = _context.People.SingleOrDefault(m => m.PersonId == id);

            person.FirstName = "Brandon";
            _context.Update(person);
            _context.SaveChanges();
        }
예제 #16
0
        public JsonResult Post(long id, [FromBody] Person person)
        {
            var oldPerson = db.Persons.Include(pn => pn.skills).FirstOrDefault(pn => pn.id == id);

            person.id = id;

            if (oldPerson != null)
            {
                if (validator.validatePerson(person))
                {
                    try
                    {
                        string oldData = ConstructPersonString(oldPerson);

                        db.Skills.RemoveRange(oldPerson.skills);
                        db.SaveChanges();
                        db.Entry(oldPerson).State = EntityState.Detached;
                        db.Entry(person).State    = EntityState.Modified;

                        foreach (var skill in person.skills)
                        {
                            skill.person = person;
                            db.Skills.Add(skill);
                        }

                        db.Update(person);
                        db.SaveChanges();

                        var newPerson = db.Persons.Include(pn => pn.skills).FirstOrDefault(pn => pn.id == id);

                        _logger.LogInformation($"success POST/PERSON/{id}");
                        _logger.LogInformation($"old data: {oldData}");
                        _logger.LogInformation($"new data: {ConstructPersonString(newPerson)}");

                        return(new JsonResult(newPerson)
                        {
                            StatusCode = StatusCodes.Status200OK
                        });
                    }
                    catch (DbUpdateException e)
                    {
                        _logger.LogError(e, $"InternalServerError POST/PERSON/{id}");
                        return(errorController.InternalError500(e.Message));
                    }
                }
                else
                {
                    _logger.LogWarning($"bad request POST/PERSON/{id}");
                    return(errorController.BadRequest400());
                }
            }
            else
            {
                _logger.LogWarning($"not found POST/PERSON/{id}");
                return(errorController.NotFound404());
            }
        }
예제 #17
0
        public IActionResult Edit(int id)
        {
            var person = _context.People.SingleOrDefault(m => m.PersonId == id);

            person.FirstName = "Brandon";
            _context.Update(person);
            _context.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
예제 #18
0
        public async Task <IActionResult> Edit(Person person)
        {
            if (ModelState.IsValid)
            {
                _context.Update(person);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(person));
        }
예제 #19
0
        public void Update(long id, Person person)
        {
            var isPersonAlive = Read(id);

            if (isPersonAlive != null)
            {
                _personContext.Update(person);
                _personContext.SaveChanges();
                Console.WriteLine("Tiedot tallennettu onnistuneesti!");
            }
            else
            {
                Console.WriteLine("Tietojen tallennus epäonnistui - henkilöä ei ole olemassa!");
            }
        }
예제 #20
0
        public async Task <IActionResult> Edit(int id, [Bind("id,Name,Position,Image,TagID")] PersonModel _person)
        {
            Person person = new Person {
                Name = _person.Name, Position = _person.Position, TagId = _person.TagId, id = id
            };

            if (id != person.id)
            {
                return(NotFound());
            }
            if (RidCheck(person.TagId))
            {
                if (_person.Image != null)
                {
                    byte[] imageData = null;

                    using (var binaryReader = new BinaryReader(_person.Image.OpenReadStream()))
                    {
                        imageData = binaryReader.ReadBytes((int)person.Image.Length);
                    }

                    person.Image = imageData;
                }
            }


            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(person);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersonExists(person.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
예제 #21
0
        public async Task <IActionResult> AddOrEdit([Bind("PersonID,FullName,ZipCode,Position,City")] Person person)
        {
            if (ModelState.IsValid)
            {
                if (person.PersonID == 0)
                {
                    _context.Add(person);
                }
                else
                {
                    _context.Update(person);
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(person));
        }
예제 #22
0
        public async Task <TEntity> UpdateAsync(TEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException($"{nameof(AddAsync)} entity must not be null");
            }

            try
            {
                _myDBContext.Update(entity);
                await _myDBContext.SaveChangesAsync();

                return(entity);
            }
            catch (Exception)
            {
                throw new Exception($"{nameof(entity)} could not be updated");
            }
        }
예제 #23
0
        static void Main(string[] args)
        {
            //Blog();
            PersonContext context = new PersonContext();
            //context.Database.EnsureDeleted();
            //context.Database.EnsureCreated();


            //context.People.Add(new Entities.Person
            //{
            //    BirthDate = DateTime.Now,
            //    FirstName = "ali",
            //    LastName = "nouri",
            //    //   Home = new Address { AddressLine = "a", PhoneNumber = "3" }
            //    //,
            //    //BankAccount = new BankAccount { AccNumber = "888800" }
            //}); ;


            //context.Teachers.Add(new Entities.Teacher
            //{
            //    //BirthDate = DateTime.Now,
            //    FirstName = "reza",
            //    LastName = "akbari",
            //    //BankAccount = new BankAccount { AccNumber = "3333" },
            //    //Home = new Address { AddressLine = "at", PhoneNumber = "dd" },
            //    Cod = "11",
            //});

            var a = context.People.Find(3);

            a.FirstName = "ddddddddddd";
            context.Update(a);
            context.SaveChanges();

            var ppa = context.People.ToList().Select(c => c.FullName);
            //var t = context.BankAccounts.ToList();
            //var ww = context.People.Include(c => c.BankAccount).ToList();
            var oo = context.Teachers.ToList();

            Console.WriteLine("");
        }
 public Person UpdatePerson(Person person)
 {
     context.Update(person);
     context.SaveChanges();
     return(person);
 }
예제 #25
0
 public void UpdatePerson(Person person)
 {
     PersonDb.Update(person);
     PersonDb.SaveChanges();
 }