Example #1
0
        public async Task <bool> Save(Vehicle vehicle)
        {
            try
            {
                _context.Entry(vehicle).State = string.IsNullOrEmpty(vehicle.Id) ? EntityState.Added : EntityState.Modified;
                _context.Vehicles.Add(vehicle);

                int affected = await _context.SaveChangesAsync();

                if (affected > 0)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                //Exception (ex) should be logged if required ..
                //Type of exceptions can be also identified and proper reaction is gonna be handled according to requirements
            }

            return(false);
        }