Esempio n. 1
0
        public virtual void Update(T entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException();
            }

            Entities.AddOrUpdate(entity);
            _context.SaveChanges();
        }
Esempio n. 2
0
 public virtual dynamic AddOrUpdate(params T[] objs)
 {
     foreach (var obj in objs)
     {
         obj.CompanyId = CompanyId;
         Entities.AddOrUpdate(obj);
     }
     SaveChanges();
     return(OperateResult.Success());
 }
 public void Update(T entity)
 {
     try
     {
         ValidateEntity(entity);
         Entities.AddOrUpdate(entity);
         _context.SaveChanges();
     }
     catch (DbEntityValidationException ex)
     {
         throw ExceptionHandler(ex);
     }
 }
Esempio n. 4
0
        public T Update(T entity)
        {
            try
            {
                if (entity == null)
                {
                    throw new ArgumentNullException("entity");
                }

                Entities.AddOrUpdate(entity);
                _context.SaveChanges();
                return(entity);
            }
            catch (DbEntityValidationException dbEx)
            {
                throw BuildException(dbEx);
            }
        }
Esempio n. 5
0
        public void Update(T entity)
        {
            try
            {
                if (entity == null)
                {
                    throw new ArgumentNullException(nameof(entity));
                }
                Entities.AddOrUpdate(entity);
                _context.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (
                    var validationError in
                    dbEx.EntityValidationErrors.SelectMany(validationErrors => validationErrors.ValidationErrors))
                {
                    _errorMessage += Environment.NewLine +
                                     $"Property: {validationError.PropertyName} Error: {validationError.ErrorMessage}";
                }

                throw new Exception(_errorMessage, dbEx);
            }
        }