Esempio n. 1
0
        public StorageOperationResult Delete(int id)
        {
            T entity = _set.Find(id);

            if (entity == null)
            {
                StorageOperationError error = new StorageOperationError(id, typeof(T).Name, "The entity requested for deletion was not found in the data storage");
                return(new StorageOperationResult()
                {
                    Errors = new StorageOperationError[] { error }
                });
            }
            _set.Remove(entity);
            try
            {
                _context.SaveChanges();
                return(new StorageOperationResult(StorageOperationResult.EmptyOperation, StorageOperationResult.EmptyOperation, new int[] { id }));
            }
            catch (DbUpdateException ex)
            {
                return(new StorageOperationResult()
                {
                    Errors = ex.Entries.Select(entry => new StorageOperationError(((T)entry.Entity).Id, typeof(T).Name, ex.Message))
                });
            }
        }
Esempio n. 2
0
        public ActionResult Delete(int?id)
        {
            StorageOperationResult result;

            if (id.HasValue)
            {
                result = _repository.Delete(id.Value);
            }
            else
            {
                StorageOperationError error = new StorageOperationError(0, null, "No Id argument received in server for delete operation");
                result = new StorageOperationResult()
                {
                    Errors = new StorageOperationError[] { error }
                };
            }
            return(PrepareUpdateResult(result));
        }
Esempio n. 3
0
        public ActionResult SaveMany(IEnumerable <T> entities)
        {
            StorageOperationResult result;

            if (entities != null)
            {
                result = _repository.SaveMany(entities);
            }
            else
            {
                StorageOperationError error = new StorageOperationError(0, null, "No data recieved in server for SaveMany operation.");
                result = new StorageOperationResult()
                {
                    Errors = new StorageOperationError[] { error }
                };
            }
            return(PrepareUpdateResult(result));
        }