예제 #1
0
        //Update person's data
        public async Task <Person> UpdateAsync(Person person)
        {
            if (!Exist(person.id))
            {
                return(new Person());
            }

            var result = await _restApiContext.person.SingleOrDefaultAsync(p => p.id.Equals(person.id));

            try
            {
                _restApiContext.Entry(result).CurrentValues.SetValues(person);
                await _restApiContext.SaveChangesAsync();
            }
            catch (Exception e)
            {
                throw e;
            }
            return(person);
        }
예제 #2
0
        public T Update(T item)
        {
            var result = dataset.SingleOrDefault(p => p.Id.Equals(item.Id));

            if (result != null)
            {
                try
                {
                    _context.Entry(result).CurrentValues.SetValues(item);
                    _context.SaveChanges();
                }
                catch (Exception)
                {
                    throw;
                }
                return(result);
            }
            else
            {
                return(null);
            }
        }